This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ask the user for a number. Depending on whether the number is even or odd, print out an appropriate message to the user. Hint: how does | |
an even / odd number react differently when divided by 2? | |
Extras: | |
1. If the number is a multiple of 4, print out a different message. | |
2. Ask the user for two numbers: one number to check (call it num) and one number to divide by (check). If check divides evenly into num, tell that to the user. If not, print a different appropriate message. | |
#My Answer: | |
number = int(input("Enter a number: ")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create a program that asks the user to enter their name and their age. Print out a message addressed to them that tells them the year that they will turn 100 years old. | |
#My Answer | |
name = input("Enter your name: ") | |
age = int(input("How old are you? ")) | |
print("{0}, you will turn 100 in {1}".format(name, 100-age)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Exercise 1: Write a program which repeatedly reads numbers until the | |
user enters “done”. Once “done” is entered, print out the total, count, | |
and average of the numbers. If the user enters anything other than a | |
number, detect their mistake using try and except and print an error | |
message and skip to the next number. | |
total = 0 | |
count = 0 | |
average = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write a program that uses input to prompt a user for their | |
name and then welcomes them. | |
name = input("Enter your name: ") # asks user for their name | |
print("Welcome {}".format(name)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Exercise 3: Write a program to prompt the user for hours and rate per | |
hour to compute gross pay. | |
Enter Hours: 35 | |
Enter Rate: 2.75 | |
Pay: 96.25 | |
hours = int(input("Enter hours worked: ")) # asks for hours worked in int | |
rate = float(input("Enter rate: ")) # asks for rate in float | |
pay = hours * rate # calculates total pay for the hours worked |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the | |
converted temperature. | |
C = float(input("Enter a celcius temperature: ")) | |
F = C *(9/5) + 32 | |
print("{0} in Fahrenheit is {1}".format(C, F)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write a program to prompt the user for hours and rate per | |
hour to compute gross pay. give the employee 1.5 | |
times the hourly rate for hours worked above 40 hours. | |
Enter Hours: 45 | |
Enter Rate: 10 | |
Pay: 475.0 | |
hours = int(input("Enter hours worked: ")) # asks user for hours worked for the week | |
rate = float(input("Enter how much you earn per hour: ")) # asks user how much per hour they get paid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Exercise 3: Write a program to prompt for a score between 0.0 and | |
1.0. If the score is out of range, print an error message. If the score is | |
between 0.0 and 1.0, print a grade using the following table: | |
Score Grade | |
>= 0.9 A | |
>= 0.8 B | |
>= 0.7 C | |
>= 0.6 D | |
< 0.6 F |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rewrite your pay program using try and except so that your | |
program handles non-numeric input gracefully by printing a message | |
and exiting the program. The following shows two executions of the | |
program: | |
Enter Hours: 20 | |
Enter Rate: nine | |
Error, please enter numeric input | |
Enter Hours: forty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write another program that prompts for a list of numbers | |
as above and at the end prints out both the maximum and minimum of | |
the numbers instead of the average. | |
largest = None | |
smallest = None | |
count = 0 | |
total = 0 | |
while True: | |
try: |
OlderNewer