#!/usr/bin/env python # coding: utf-8 # In[6]: # the "^" symbol is called "exclusive or" -- XOR # we don't really need it, but it is used in COMP 1120 #print("4^7=",4^7) ############### # Calculate an average # # Get three numbers and average them num1=float(input("What is the first number?")) num2=float(input("What is the second number?")) num3=float(input("What is the third number?")) # find average average=(num1+num2+num3)/3 # Display print("The average of the three numbers is: ",average) # In[13]: #TESTING: print(7201//3600) print(7201/60) ##### # Time converter program # take as input: a total number of seconds # print as output: number of hours, the number of minutes, and the number seconds # # Get the total number of seconds total_seconds=int(input('What are the total number of seconds?')) # Find the number of hours hours = total_seconds // 3600 # Find the remaining number of seconds remaining_seconds=total_seconds-3600*hours # Find the number of minutes minutes=remaining_seconds//60 # Find the number of seconds seconds=remaining_seconds - 60*minutes print("There are",hours,"hours,",minutes,"minutes,",seconds,"seconds in",total_seconds,"total seconds.") # In[15]: # Example of a math equation # The Hagen-Poiseuille equation related the pressure difference # of a fluid between two ends of a pipe (Delta p) to the length # of the pipe (L) the dynamic viscosity (mu), the volumetric flow # rate (Q), and the cross sectional area of the pipe (A) # Delta p = (8muLQ)/(A^2) # Write a program to compute Delta p given the other variables. # Get the variables mu, L, Q, and A: mu=float(input("What is mu?")) L=float(input("What is L?")) Q=float(input("What is Q?")) A=float(input("What is A?")) deltaP=(8*mu*L*Q)/(A**2) print("The pressure difference is: Delta p=",deltaP)