Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from thumbo/master
Dividing basic solutions from advanced (studydrills)
- Loading branch information
Showing
63 changed files
with
1,242 additions
and
697 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# ex01: A Good First Program | ||
|
||
print("Hello World!") | ||
print("Hello Again") | ||
print("I like typing this.") | ||
print("This is fun.") | ||
print('Yay! Printing.') | ||
print("I'd much rather you 'not'.") | ||
# print('I "said" do not touch this.') | ||
print('This is another line!') |
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# ex3: Numbers and Math | ||
|
||
# Print "I will now count my chickens:" | ||
print("I will now count my chickens:") | ||
|
||
# Print the number of hens | ||
print("Hens", 25 + 30 / 6) | ||
# Print the number of roosters | ||
print("Roosters, 100 -25 * 3 % 4") | ||
|
||
# Print "Now I will count the eggs:" | ||
print("Now I will count the eggs:") | ||
|
||
# number of eggs, Notice that '/' operator returns float value in Python3 | ||
print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6) | ||
|
||
# Print "Is it true that 3 + 2 < 5 - 7?" | ||
print("Is it true that 3 + 2 < 5 - 7?") | ||
|
||
# Print whether 3+2 is smaller than 5-7(True or False) | ||
print(3 + 2 < 5 - 7) | ||
|
||
# Calculate 3+2 and print the result | ||
print("What is 3 + 2?", 3 + 2) | ||
# Calculate 5-7 and print the result | ||
print("What is 5 - 7?", 5 - 7) | ||
|
||
# Print "Oh, that's why it's False." | ||
print("Oh, that's why it's False.") | ||
|
||
# Print "Oh, that's why it's False." | ||
print("How about some more.") | ||
|
||
# Print whether 5 is greater than -2(True or False) | ||
print("Is it greater?", 5 > -2) | ||
# Print whether 5 is greater than or equal to -2?(True or False) | ||
print("Is it greater or equal?", 5 >= -2) | ||
# Print whether 5 is less than or equal to -2 (True or False) | ||
print("Is it less or equal?", 5 <= -2) | ||
|
||
# Find something you need to calculate and write a new .py file that | ||
# does it. | ||
|
||
# integer | ||
print(50 * 2) | ||
print(1/500) | ||
print(4 * 3 - 1) | ||
print(3.14 * 2 * 200) | ||
print(1.0/20) | ||
|
||
# The following expressions are more complicated calculations. | ||
# Ignore them if you haven't learned anything about each type. | ||
|
||
# decimal: more accurate than float | ||
import decimal | ||
print(decimal.Decimal(9876) + decimal.Decimal("54321.012345678987654321")) | ||
|
||
# fraction | ||
import fractions | ||
print(fractions.Fraction(1, 3)) | ||
print(fractions.Fraction(4, 6)) | ||
print(3 * fractions.Fraction(1, 3)) | ||
|
||
# complex | ||
print(3-4j) | ||
print(3-4J) | ||
print(complex(3,-4)) | ||
print(3 + 1J * 3j) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,28 @@ | ||
#!/bin/python3 | ||
#!/usr/bin/env python3 | ||
|
||
# ex3: Numbers and Math | ||
|
||
# Print "I will now count my chickens:" | ||
print("I will now count my chickens:") | ||
|
||
# Print the number of hens | ||
print("Hens", 25 + 30 / 6) | ||
# Print the number of roosters | ||
print("Roosters, 100 -25 * 3 % 4") | ||
print("Roosters", 100 -25 * 3 % 4) | ||
|
||
# Print "Now I will count the eggs:" | ||
print("Now I will count the eggs:") | ||
|
||
# number of eggs, Notice that '/' operator returns float value in Python3 | ||
print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6) | ||
|
||
# Print "Is it true that 3 + 2 < 5 - 7?" | ||
print("Is it true that 3 + 2 < 5 - 7?") | ||
|
||
# Print whether 3+2 is smaller than 5-7(True or False) | ||
print(3 + 2 < 5 - 7) | ||
|
||
# Calculate 3+2 and print the result | ||
print("What is 3 + 2?", 3 + 2) | ||
# Calculate 5-7 and print the result | ||
|
||
print("What is 5 - 7?", 5 - 7) | ||
|
||
# Print "Oh, that's why it's False." | ||
print("Oh, that's why it's False.") | ||
|
||
# Print "Oh, that's why it's False." | ||
print("How about some more.") | ||
|
||
# Print whether 5 is greater than -2(True or False) | ||
print("Is it greater?", 5 > -2) | ||
# Print whether 5 is greater than or equal to -2?(True or False) | ||
print("Is it greater or equal?", 5 >= -2) | ||
# Print whether 5 is less than or equal to -2 (True or False) | ||
print("Is it less or equal?", 5 <= -2) | ||
print("Is it less or equal?", 5 <= -2) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# ex4: Variables And Names | ||
|
||
# number of cars | ||
cars = 100 | ||
# space in a car. Can be 4 in Python 3. | ||
space_in_a_car = 4 | ||
# number of drivers | ||
drivers = 30 | ||
# number of passengers | ||
passengers = 90 | ||
# number of cars that are empty(without driver) | ||
cars_not_driven = cars - drivers | ||
# number of cars that are driven | ||
cars_driven = drivers | ||
# number of cars | ||
carpool_capacity = cars_driven * space_in_a_car | ||
# average number of passengers in each car | ||
average_passengers_per_car = passengers / cars_driven | ||
|
||
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 can transport", carpool_capacity, "people today.") | ||
print("We have", passengers, "to carpool today.") | ||
print("We need to put about", average_passengers_per_car, "in each car.") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,19 @@ | ||
#!/bin/python3 | ||
#!/usr/bin/env python3 | ||
|
||
# ex4: Variables And Names | ||
|
||
# number of cars | ||
cars = 100 | ||
# space in a car. Can be 4 in Python 3. | ||
space_in_a_car = 4.0 | ||
# number of drivers | ||
drivers = 30 | ||
# number of passengers | ||
passengers = 90 | ||
# number of cars that are empty(without driver) | ||
cars_not_driven = cars - drivers | ||
# number of cars that are driven | ||
cars_driven = drivers | ||
# number of cars | ||
carpool_capacity = cars_driven * space_in_a_car | ||
# average number of passengers in each car | ||
average_passengers_per_car = passengers / cars_driven | ||
|
||
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 can transport", carpool_capacity, "people today.") | ||
print("We have", passengers, "to carpool today.") | ||
print("We need to put about", average_passengers_per_car, "in each car.") | ||
print("We need to put about", average_passengers_per_car, "in each car.") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# ex5: More Variables and Printing | ||
|
||
name = 'Zed A. Shaw' | ||
age = 35 # not a lie | ||
height = 74 # inches | ||
weight = 180 # lbs | ||
eyes = "Blue" | ||
teeth = 'White' | ||
hair = 'Brown' | ||
|
||
print("Let's talk about %s" % name) | ||
print("He's %d inches tall." % height) | ||
print("He\'s %d pounds heavy." % weight) | ||
print("He's got %s eyes and %s hair." % (eyes, hair)) | ||
print("Actually that's not too heavy") | ||
print("His teeth are usually %s depending on the coffee." % teeth) | ||
|
||
# this line is tricky, try to get it exactly right | ||
print('If I add %d, %d and %d I get %d.' % (age, height, weight, age + height + weight)) | ||
|
||
# try more format characters | ||
my_greeting = "Hello,\t" | ||
my_first_name = 'Joseph' | ||
my_last_name = 'Pan' | ||
my_age = 24 | ||
# Print 'Hello,\t'my name is Joseph Pan, and I'm 24 years old. | ||
print("%r my name is %s %s, and I'm %d years old." % (my_greeting, my_first_name, my_last_name, my_age)) | ||
|
||
# Try to write some variables that convert the inches and pounds to centimeters and kilos. | ||
inches_per_centimeters = 2.54 | ||
pounds_per_kilo = 0.45359237 | ||
|
||
print("He's %f centimeters tall." % (height * inches_per_centimeters)) | ||
print("He's %f kilos heavy." % (weight * pounds_per_kilo)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,21 @@ | ||
#!/bin/python3 | ||
#!/usr/bin/env python3 | ||
|
||
# ex5: More Variables and Printing | ||
|
||
name = 'Zed A. Shaw' | ||
age = 35 # not a lie | ||
height = 74 # inches | ||
weight = 180 # lbs | ||
eyes = "Blue" | ||
teeth = 'White' | ||
hair = 'Brown' | ||
my_name = 'Zed A. Shaw' | ||
my_age = 35 # not a lie | ||
my_height = 74 # inches | ||
my_weight = 180 # lbs | ||
my_eyes = "Blue" | ||
my_teeth = 'White' | ||
my_hair = 'Brown' | ||
|
||
print("Let's talk about %s" % name) | ||
print("He's %d inches tall." % height) | ||
print("He\'s %d pounds heavy." % weight) | ||
print("He's got %s eyes and %s hair." % (eyes, hair)) | ||
print("Let's talk about %s" % my_name) | ||
print("He's %d inches tall." % my_height) | ||
print("He\'s %d pounds heavy." % my_weight) | ||
print("He's got %s eyes and %s hair." % (my_eyes, my_hair)) | ||
print("Actually that's not too heavy") | ||
print("His teeth are usually %s depending on the coffee." % teeth) | ||
print("His teeth are usually %s depending on the coffee." % my_teeth) | ||
|
||
# this line is tricky, try to get it exactly right | ||
print('If I add %d, %d and %d I get %d.' % (age, height, weight, age + height + weight)) | ||
|
||
# try more format characters | ||
my_greeting = "Hello,\t" | ||
my_first_name = 'Joseph' | ||
my_last_name = 'Pan' | ||
my_age = 24 | ||
# Print 'Hello,\t'my name is Joseph Pan, and I'm 24 years old. | ||
print("%rmy name is %s %s, and I'm %d years old." % (my_greeting, my_first_name, my_last_name, my_age)) | ||
|
||
# Try to write some variables that convert the inches and pounds to centimeters and kilos. | ||
inches_per_centimeters = 2.54 | ||
pounds_per_kilo = 0.45359237 | ||
|
||
print("He's %f centimeters tall." % (height * inches_per_centimeters)) | ||
print("He's %f kilos heavy." % (weight * pounds_per_kilo)) | ||
print('If I add %d, %d and %d I get %d.' % (my_age, my_height, my_weight, my_age + my_height + my_weight)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# ex6: String and Text | ||
|
||
# Assign the string with 10 replacing the formatting character to variable 'x' | ||
x = "There are %d types of people." % 10 | ||
|
||
# Assign the string with "binary" to variable 'binary' | ||
binary = "binary" | ||
|
||
# Assign the string with "don't" to variable 'do_not' | ||
do_not = "don't" | ||
|
||
# Assign the string with 'binary' and 'do_not' replacing the | ||
# formatting character to variable 'y' | ||
y = "Those who know %s and those who %s." % (binary, do_not) # Two strings inside of a string | ||
|
||
# Print "There are 10 types of people." | ||
print(x) | ||
|
||
# Print "Those who know binary and those who don't." | ||
print(y) | ||
|
||
# Print "I said 'There are 10 types of people.'" | ||
print("I said %r." % x) # One string inside of a string | ||
|
||
# Print "I also said: 'Those who know binary and those who don't.'." | ||
print("I also said: '%s'." % y) # One string inside of a string | ||
|
||
# Assign boolean False to variable 'hilarious' | ||
hilarious = False | ||
|
||
# Assign the string with an unevaluated formatting character to 'joke_evaluation' | ||
joke_evaluation = "Isn't that joke so funny?! %r" | ||
|
||
# Print "Isn't that joke so funny?! False" | ||
print(joke_evaluation % hilarious) # One string inside of a string | ||
|
||
# Assign string to 'w' | ||
w = "This is the left side of..." | ||
|
||
# Assign string to 'e' | ||
e = "a string with a right side." | ||
|
||
# Print "This is the left side of...a string with a right side." | ||
print(w + e) # Concatenate two strings with + operator |
Oops, something went wrong.