Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS-UY 1114 / Python

First Midterm Exam – 23 Oct 2018

1)   (12 points) Perform the following conversions. You may use the space below each part for calculations.

a.    (2 pts) Convert the binary number 11101011 to decimal: ____________________

b.   (2 pts) Convert the decimal number 151 to binary: ___________________

c.   (2 pts) Convert the binary number 10011100 to hexadecimal: _______________

d.   (2 pts) Convert the hexadecimal number 5F to binary: ____________________ (please show all 8 binary digits)

e.   (4 pts) Convert the decimal number 90 to hexadecimal: ____________________

2)   (18 pts; 3 each) Given the assignment statements below, evaluate the following expressions. If the expression cannot be evaluated as written, choose invalid.” Circle your answer for each.

x = True

y = True

z = False

i = 4

j = 0

k = -2

i > j > k

x or (y and z)

not(k =< k)

'a ' < 'b '

j < i and y

x and not(j < i)

3)   (15 points) What is the output from the following code?

char = "C"

for i in range(1, 6):

if i % 3 == 0:

char = "A"

elif i % 2 == 0:

char = "B"

print(char * i)

4)   (10 points) What is the output from the following code if the user enters 75?

c=int(input('enter a value: '))

if c > 100:

print("A")

elif c > 50:

if c % 5 == 0 and not(c % 10 == 0):

print("B")

elif c % 5 == 0:

print("C")

else:

print("D")

if c > 20:

print("E")

else:

print("F")

(10 Points) What is the output from the following code?

for i in range(10, 4, -2):

j = i + 1

while j % 3 != 0:

print ("i=", i ,"j=", j)

j += 1

6)    (10 pts) In New York State, employees are classified as either tipped or non-tipped. A non-tipped employee (such as a computer programmer) has a minimum wage of $13 per hour. A tipped         employee (such as a waiter) has a minimum wage of $8.65 per hour.

Write a program to ask the user for the employee's hourly wage and whether or not they are a   tipped employee (where the input "y" means that they are tipped, and anything else means they aren't). Then the program should print to the screen whether the stated wage is legal (i.e. not     below the minimum wage for that category of employee). The output of the program should be Legal or Illegal.

Sample Runs:

What is the pay rate? 13.00

Tipped employee (y/n)? n

Legal

What is the pay rate? 8.90

Tipped employee (y/n)? y

Legal

What is the pay rate? 5.00

Tipped employee (y/n)? y

Illegal

What is the pay rate? 20.00

Tipped employee (y/n)? y

Legal

7)  (25 pts) Write a program that prompts the user to enter a sequence of positive integers where each integer represents how many hours the employee worked in a day this week. When the user enters a negative integer, there are no more days to input. The program should then print out (a) the employee's bonus pay for that week; (b) the employee's overtime pay for that week; and (c) the employee's total pay for that week.

The rules governing an employee's pay are as follows:

●    Each employee has an hourly pay rate, which we will call payRate. An employee is      paid payRate dollars for every hour worked.  payRate is a variable defined for you in advance; you should not define it or read it in.

●    If an employee works more than 10 hours in a single day, they must be paid an additional bonus of $13 for each such day.

●    If an employee works a total of more than 40 hours in a single week, any hours over 40  will be paid at an overtime rate of one-and-a-half times their usual hourly wage. Hours   under 40 will be paid at the usual rate. For example, if an employee has a normal rate of $10 per hour and works 45 hours in a single week, they will be paid $10 x 40 = $400 for the first 40 hours, then an additional overtime of 1.5 x $10 x 5 = $75 for the remaining 5 hours, for a total pay of $475.

The formatting and number of decimal places output in your calculations are not taken into account in grading your work.

(In the following examples, payRate is 10.0.)

Enter the hours worked:

10

-1

Bonus Pay: $0.0

Overtime Pay: $0.0

Total Pay: $100.0

Enter the hours worked:

10

11

-1

Bonus Pay: $13.0

Overtime Pay: $0.0

Total Pay: $223.0

Enter the hours worked:

20

20

5

-1

Bonus Pay: $26.0

Overtime Pay: $75.0

Total Pay: $501.0

Enter the hours worked:

20

20

-1

Bonus Pay: $26.0

Overtime Pay: $0.0

Total Pay: $426.0