# 07-Exam 1 Review - CS 1114, Spring 2022

AI悦创原创PythonPython一对一教学Python一对一辅导Python 辅导编程一对一教学少儿编程一对一NYU编程辅导NYU Python辅导PythonPython一对一教学Python一对一辅导Python 辅导编程一对一教学少儿编程一对一NYU编程辅导NYU Python辅导大约 8 分钟...约 2432 字

## # Exam 1 Review - CS 1114, Spring 2022

Disclaimer: This mock exam is only for practice. It was made by tutors in the Polytechnic Tutoring Center and is not representative of the actual exam given by the CS Department.

## # Question 1

1. Given these assignments: a = 5, b = 2, and s = 1.5 write the type and value of the following expressions. Circle ERROR if the expression will result in a run time error.

Statement:Type:Value:ERROR:
`a / b`
`b ** a`
`float(a) / b`
`a % b`
`s // a`
`a => b`
`a == b`
`a // b`
`a + b * a`

## # Question 2

1. Conversion between binary, decimal and hexadecimal numbers:

a. Convert the binary number 11101011 to decimal: ____________________

``````"""
1   1   1   0   1   0   1   1
7   6   5   4   3   2   1   0
1*(2**7) + 1*(2**6) + 1*(2**5) + 0 + 1*(2**3) + 0 + 1*(2**1) + 1

"""
print(1*(2**7) + 1*(2**6) + 1*(2**5) + 0 + 1*(2**3) + 0 + 1*(2**1) + 1)
``````

b. Convert the decimal number 151 to binary: ____________________

c. Convert the binary number 10011100 to hexadecimal:____________________

1001 1100

``````二进制数   十六进制数
0000      0
0001      1
0010      2
0011      3
0100      4
0101      5
0110      6
0111      7
1000      8
1001      9
1010      A
1011      B
1100      C
1101      D
1110      E
1111      F
``````

`1001 1100 = 9C`

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

``````十六进制数   二进制数
0           0000
1           0001
2           0010
3           0011
4           0100
5           0101
6           0110
7           0111
8           1000
9           1001
A           1010
B           1011
C           1100
D           1101
E           1110
F           1111
``````

``````5 = 0101
F = 1111
``````

`01011111`

e. Convert the decimal number 90 to hexadecimal:____________________

``````十进制数   十六进制数
0          0
1          1
2          2
3          3
4          4
5          5
6          6
7          7
8          8
9          9
10         A
11         B
12         C
13         D
14         E
15         F
``````

• 90 / 16 = 5 余 10，因此最低位为 A。
• 5 / 16 = 0 余 5，因此次低位为 5。
• 商为 0，所以转换完成。

## # Question 3

1. 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")
``````

## # Question 4

1. What is the output from the following code ?

``````acc = 0
for i in range(5, 15, 5):
var = i
while var > 0:
var //= 2
acc += var
print("i=", i, "var=", var)
print("acc", acc)
``````

## # Question 5

Write a program that prompts for radius length. Your program should calculate and print the resulting circumference (float) and area (float) of a circle with that radius. You must also check that the given radius is positive. Otherwise, print an error message and do not carry out the calculations. Use pi = 3.14 for this question rather than importing the math module.

``````Sample Outputs 1:
Circumference: 18.84
Area: 28.26

Sample Outputs 2:
``````

## # Question 6

Write a program that prompts a row number and print out the pattern in a zig-zag way. If the leading number of the row is odd, the row displays numbers in a decreasing sequence, starting from the leading number to 1. If the leading number of the row is even, the row displays numbers in an increasing sequence, starting from 1 to the leading number. Assume the input is always a valid positive integer.

``````Sample Output 1:
Enter # of row:  5
5 4 3 2 1
1 2 3 4
3 2 1
1 2
1
``````
``````Sample Output 2:
Enter # of row: 4
4 3 2 1
3 2 1
1 2
1
``````

``````row = int(input("Enter # of row: "))

for i in range(row, 0, -1):
if i % 2 == 1:
for j in range(i, 0, -1):
print(j, end=" ")
else:
for j in range(1, i + 1):
print(j, end=" ")
print()
``````

## # Question 7

Given a positive integer number, write a program to print the total number of times each digit. 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. However, since there is a maximum of 7 days in a week, so at most you can take inputs for 7 times. 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:

a. 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.

a.每个员工都有一个小时工资率，我们称之为payRate。员工每工作一小时支付payRate美元。payRate是预先为您定义的变量;你不应该定义它，也不应该读入它。

b. 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.

b.如果一名员工在一天内工作超过10小时，他们必须获得额外的奖金，每天13美元。

c. 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 output in your calculations should be rounded to 2 decimal places if the output is more than 2 decimal places.

(In the following examples, payRate is 10.275.)

## # Sample outputs:

AI悦创·编程一对一

AI悦创·推出辅导班啦，包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」，全部都是一对一教学：一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然，还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线，随时响应！微信：Jiabcdefh

C++ 信息奥赛题解，长期更新！长期招收一对一中小学信息奥赛集训，莆田、厦门地区有机会线下上门，其他地区线上。微信：Jiabcdefh

• 0
• 0
• 0
• 0
• 0
• 0

• 按正序
• 按倒序
• 按热度