<filename>Chapter2.py
##################
# 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:')
# >>> Enter your name: Chuck
print('Hello', name)
# >>> Hello Chuck


##################
# 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

# We won’t worry about making sure our pay has exactly two digits after the decimal place for now. 
# If you want, you can play with the built-in Python round function to properly round the resulting pay to two decimal places.

hours = input('Enter hours:')
# >>> Enter hours: 35
rate = input('Enter rate:')
# >>> Enter rate: 2.75
pay = float(hours)*float(rate)
print('Pay:', pay)
# >>> Pay: 96.25

# My code works, but let's make it a bit more succinct.
 
hours = float(input('Enter hours '))
# >>> Enter hours: 35 
rate = float(input('Enter rate '))
# >>> Enter rate: 2.75
print(hours * rate)
# >>> Pay: 96.25


##################
# 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).
# 1. width//2
# 2. width/2.0
# 3. height/3
# 4. 1 + 2 * 5

#Use the Python interpreter to check your answers

width = float(input("Enter the Width: "))
# >>> Enter the Width: 17
height = float(input("Enter the Height: "))
# >>> Enter the Height: 12.0

print("Value is : ", width // 2, "and type is: " , type(width // 2)) 
# >>> Value is :  8.0 and type is:  <class 'float'>
print("Value is : ", width / 2.0, "and type is: " , type(width / 2.0))
# >>> Value is :  8.5 and type is:  <class 'float'>
print("Value is : ", width / 3 ,"and type is: " , type(width / 3))
# >>> Value is :  5.666666666666667 and type is:  <class 'float'>
print("Value is :" , 1 + 2 * 5,"and type is: " , type(1 + 2 * 5))
# >>> Value is : 11 and type is:  <class 'int'>
    

##################
# 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 = float(input("Enter temperature in celsius: "))
# >>> Enter temperature in celsius: 22
fahrenheit = (celsius * 9/5) + 32
print('%.2f Celsius is: %0.2f Fahrenheit' %(celsius, fahrenheit))
# >>> 22.00 Celsius is: 71.60 Fahrenheit


##################

<filename>Chapter2.py
##################
# 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:')
# >>> Enter your name: Chuck
print('Hello', name)
# >>> Hello Chuck


##################
# 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

# We won’t worry about making sure our pay has exactly two digits after the decimal place for now. 
# If you want, you can play with the built-in Python round function to properly round the resulting pay to two decimal places.

hours = input('Enter hours:')
# >>> Enter hours: 35
rate = input('Enter rate:')
# >>> Enter rate: 2.75
pay = float(hours)*float(rate)
print('Pay:', pay)
# >>> Pay: 96.25

# My code works, but let's make it a bit more succinct.
 
hours = float(input('Enter hours '))
# >>> Enter hours: 35 
rate = float(input('Enter rate '))
# >>> Enter rate: 2.75
print(hours * rate)
# >>> Pay: 96.25


##################
# 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).
# 1. width//2
# 2. width/2.0
# 3. height/3
# 4. 1 + 2 * 5

#Use the Python interpreter to check your answers

width = float(input("Enter the Width: "))
# >>> Enter the Width: 17
height = float(input("Enter the Height: "))
# >>> Enter the Height: 12.0

print("Value is : ", width // 2, "and type is: " , type(width // 2)) 
# >>> Value is :  8.0 and type is:  <class 'float'>
print("Value is : ", width / 2.0, "and type is: " , type(width / 2.0))
# >>> Value is :  8.5 and type is:  <class 'float'>
print("Value is : ", width / 3 ,"and type is: " , type(width / 3))
# >>> Value is :  5.666666666666667 and type is:  <class 'float'>
print("Value is :" , 1 + 2 * 5,"and type is: " , type(1 + 2 * 5))
# >>> Value is : 11 and type is:  <class 'int'>
    

##################
# 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 = float(input("Enter temperature in celsius: "))
# >>> Enter temperature in celsius: 22
fahrenheit = (celsius * 9/5) + 32
print('%.2f Celsius is: %0.2f Fahrenheit' %(celsius, fahrenheit))
# >>> 22.00 Celsius is: 71.60 Fahrenheit


##################

################## # 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 # >>> Enter your name: Chuck # >>> Hello Chuck ################## # 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 # We won’t worry about making sure our pay has exactly two digits after the decimal place for now. # If you want, you can play with the built-in Python round function to properly round the resulting pay to two decimal places. # >>> Enter hours: 35 # >>> Enter rate: 2.75 # >>> Pay: 96.25 # My code works, but let's make it a bit more succinct. # >>> Enter hours: 35 # >>> Enter rate: 2.75 # >>> Pay: 96.25 ################## # 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). # 1. width//2 # 2. width/2.0 # 3. height/3 # 4. 1 + 2 * 5 #Use the Python interpreter to check your answers # >>> Enter the Width: 17 # >>> Enter the Height: 12.0 # >>> Value is :  8.0 and type is:  <class 'float'> # >>> Value is :  8.5 and type is:  <class 'float'> # >>> Value is :  5.666666666666667 and type is:  <class 'float'> # >>> Value is : 11 and type is:  <class 'int'> ################## # Exercise 5: Write a program which prompts the user for a Celsius temperature, # convert the temperature to Fahrenheit, and print out the converted temperature. # >>> Enter temperature in celsius: 22 # >>> 22.00 Celsius is: 71.60 Fahrenheit ##################