From a4bbf1887b60e7917c1a37e90e0715bb24ade7cb Mon Sep 17 00:00:00 2001 From: Josh Mudge Date: Fri, 31 Aug 2018 17:47:16 -0600 Subject: [PATCH] 4 Exercises --- ex1.py | 11 +++++++++++ ex2.py | 20 ++++++++++++++++++++ ex3.py | 23 +++++++++++++++++++++++ ex4.py | 27 +++++++++++++++++++++++++++ newfile.py | 0 5 files changed, 81 insertions(+) create mode 100644 ex1.py create mode 100644 ex2.py create mode 100644 ex3.py create mode 100644 ex4.py create mode 100644 newfile.py diff --git a/ex1.py b/ex1.py new file mode 100644 index 0000000..5329fd6 --- /dev/null +++ b/ex1.py @@ -0,0 +1,11 @@ +print "Hello World!" +print "Hello Again" +print "I like typing this." +print "This is fun" +print "Yo yo yo" +print "Printing along with the instructions" +print "But I rebelled slightly." +print "I did more than he said and different starting with yo." +print "" +print "Yo!" +print #"hi" diff --git a/ex2.py b/ex2.py new file mode 100644 index 0000000..c6a7a9f --- /dev/null +++ b/ex2.py @@ -0,0 +1,20 @@ +# Comments for reading how your program works later. + + + +print "Code before comments" # Prints "Code before comments" + +# Disabled code. Non-functional +# print "Won't run." + +print "This will run." + +# A comment, this is so you can read your program later. +# Anything after the # is ignored by python. + +print "I could have code like this." # and the comment after is ignored. + +# You can also use a comment to "disable" or comment out a piece of code: +# print "This won't run." + +print "This will run." diff --git a/ex3.py b/ex3.py new file mode 100644 index 0000000..4567378 --- /dev/null +++ b/ex3.py @@ -0,0 +1,23 @@ +print "I will now count my chickens:" # Prints text + +print "Hens", 25.0 + 30.0 / 6.0 # Divides, then adds the numbers together. +print "Roosters", 100.0 - 25.0 * 3.0 % 4.0 # Multiplies 25 and 3, then runs 75 mod 4 which is 3, then subtracts that from 10.00.0. + +print "Now I will count the eggs:" # More text. + +print 3.0 + 2.0 + 1.0 - 5.0 + 4.0 % 2.0 - 1.0 / 4.0 + 6.0 # + +print "Is it true that 3 + 2 < 5 - 7" + +print 3.0 + 2.0 < 5.0 - 7.0 + +print "What is 3 +2?", 3.0 + 2.0 +print "What is 5 -7?", 5.0 - 7.0 + +print "That's why it's False." + +print "How about some more?" + +print "Is it greater?", 5.0 > -2.0 +print "Is it greater or equal?", 5.0 >= -2.0 +print "Is it less or equal?", 5.0 <= -2.0 diff --git a/ex4.py b/ex4.py new file mode 100644 index 0000000..cbba265 --- /dev/null +++ b/ex4.py @@ -0,0 +1,27 @@ +# Number of cars +cars = 100 +# Number of people that can be fit in each car. +space_in_a_car = 4.0 +# Number of people driving. +drivers = 30 +# Number of passengers riding. +passengers = 90 +# Number of cars not driven. +cars_not_driven = cars - drivers +# Number of cars driven. +cars_driven = drivers +# The total number of people that can ride in each car. +carpool_capacity = cars_driven * space_in_a_car +# The average number of passengers in each car. +average_passengers_per_car = passengers / cars_driven # Line number 8, the first time, he tried to do car_pool_capacity instead of carpool_capacity + +print "There are", cars, "cars available." +print "There are only", drivers, "drivers available." +print "There will be", cars_not_driven, "empty cars today." +print "We have", passengers, "to carpool today." +print "We need to put about", average_passengers_per_car, "in each car." + +# 1. I used 4.0 for space_in_a_car, but is that necessary? What happens if it's just 4? Nothing changes in this case. +# 2. Remember that 4.0 is a floating point number. It's just a number with a decimal point, and you need 4.0 instead of just 4 so that it is floating point. +# 3. Write comments above each of the variable assignments. +# 4-6 completed as well. diff --git a/newfile.py b/newfile.py new file mode 100644 index 0000000..e69de29