在参加Coursera课程的时候,老师提供的材料书里的相关代码练习。
- Exercise 2: Write a program that uses input to prompt a user for their name and then welcomes them.
Enter your name: Chuck
Hello Chuck
name=input('Enter your name:')
print('Hello',name)
- 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=input('Enter Hours: ')
rate=input('Enter Rate: ')
pay=float(hours)*float(rate)
print('Pay:',pay)
- Exercise 4: Assume that we execute the following assignment statements:
width = 17
height = 12.0
For each of the following expressions, write the value of the expression and the type (of the value of the expression).
-
width//2
-
width/2.0
-
height/3
-
1 + 2 * 5
- Exercise 5: Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the converted temperature.
Celsius=input('Celsius is: ')
Fahrenheit=float(Celsius)*9/5+32
print('Fahrenheit is= ',Fahrenheit)