You are on page 1of 7

Write a Python program that asks user the current speed (suppose user is travelling in a

car). If the speed is greater than 70 mph, print out the warning message Slow Down!.

Hint: don't forget to indent the statements inside the if block (In Canvas, the "Tab"
key is not adding spaces for you, you have to manually type a number of
"SPACE" keys).

[Run your program in Python IDLE to get rid of syntax errors and verify if the
program works correctly as described above. Program that cannot run due to
syntax error(s) will receive 0 point. ]

Your Answer:

speed = int(input("What is your current speed (mph): "))

if speed > 70:

print("Slow Down!")

Question 2
40 / 50 pts

Write a Python program that asks user the current speed (suppose user is travelling in a
car). If the speed is greater than 70 mph, print out the warning message Slow Down!;
Otherwise, print out the message Maintain the current speed!.

Note that: if-else structure must be used (only one keyword if can be used).

[Run your program in Python IDLE to get rid of syntax errors and verify if the
program works correctly as described above. Program that cannot run due to
syntax error(s) will receive 0 point. ]

Your Answer:

speed = int(input("What is your current speed (mph): "))

if speed > 70:

print("Slow Down!")
else:

print('Maintain the current speed!')

Question 3

40 / 50 pts

Write a Python program that asks user the current speed (suppose user is travelling in a
car). If the speed is greater than 70 mph, print out the warning message Slow Down!; If
the speed is lower than or equal to 20 mph, print out the warning message Speed up!;
Otherwise, print out the message Maintain the current speed!.

Note that: if-elif-else structure must be used (only one keyword if can be used).

[Run your program in Python IDLE to get rid of syntax errors and verify if the
program works correctly as described above. Program that cannot run due to
syntax error(s) will receive 0 point. ]
Your Answer:

speed = int(input("What is your current speed (mph): "))

if speed > 70:

print("Slow Down!")

elif speed <= 20:

print("Speed up!")

else:

print('Maintain the current speed!')

Question 4

40 / 50 pts

Write a Python program that first asks user to enter three integer numbers. Then,
determine and and print out the smallest one.

Note that the if-elif-else structure and proper logical operator(s) must be used. Only
one if keyword can appear in your program and the nested decision structure is
NOT allowed.
[Run your program in Python IDLE to get rid of syntax errors and verify if the
program works correctly as described above. Program that cannot run due to
syntax error(s) will receive 0 point. ]

Your Answer:

n1 = int(input("Enter the first number: "))

n2 = int(input("Enter the second number: "))

n3 = int(input("Enter the third number: "))

if n1 <= n2 and n1 <= n3:

print("The smallest number is", n1)

elif n2 <= n1 and n2 <= n3:

print("The smallest number is", n2)

else:
print("The smallest number is", n3)

Question 5

20 / 0 pts

[This is an extra credit question (25 Pts), credits are given only to submissions
before the due]

Write a Python program that first asks user to enter three integer numbers. Then, it
identifies and prints out the median (middle) number of the three entered numbers
(which is in the middle by value).

Note that the if-elif-else structure and proper logical operator(s) must be used. Only
one if keyword can appear in your program and the nested decision structure is
NOT allowed.

[Run your program in Python IDLE to get rid of syntax errors and verify if the
program works correctly as described above. Program that cannot run due to
syntax error(s) will receive 0 point. ]
Your Answer:

n1 = int(input("Enter the first number: "))

n2 = int(input("Enter the second number: "))

n3 = int(input("Enter the third number: "))

if (n1 <= n2 and n1 >= n3) or (n1 >= n2 and n1 <= n3):

print("The median number is", n1)

elif (n2 <= n1 and n2 >= n3) or (n2 >= n1 and n2 <= n3):

print("The median number is", n2)

else:

print("The median number is", n3)

You might also like