-
-
Save narainravi24/1028f3e2325e3eece1ed49ff6a346615 to your computer and use it in GitHub Desktop.
Introduction to Python - Unit 1 Absolute Beginner
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
# Task 2 use a print() function with comma separation to combine 2 numbers and 2 strings | |
print("I'm picking you up at",16, "sharp not at ", 17,"Rember!") | |
# Task 3 display text describing an address, made from stings and variables of different | |
street = input ( "What is the name of your street?") | |
str_number = input ("And the number?") | |
print ("So it is", street, str_number) | |
# Task 4[ ] define a variable with a string or numeric value | |
num_newst = 50 | |
# Task 4 [ ] display a message combining the variable, 1 or more literal strings and a number | |
print ("Today, we are gather to welcome", num_newst, " to the faculty") |
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
# [ ] get input for variables: owner, num_people, training_time - use descriptive prompt text | |
owner = input ("For whom is the reservation?") | |
num_people = input ("How many people?") | |
training_time = input ("At what time?") | |
# [ ] create a integer variable min_early and "hard code" the integer value (e.g. - 5, 10 or 15) | |
min_early = 10 | |
# [ ] print reminder text using all variables & add additional strings - use comma separated print formatting | |
print ("Reminder - The reservation is made by",owner,",for",num_people,"at",training_time,".Please be there", min_early,"minutes earlier") |
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
# menu | |
menu = "salad, pasta, sandwich, pizza, drinks, dessert" | |
print("Sir the menu is the following: ", menu) | |
# get user input for add_item variable | |
print("May I have an Hamburger") | |
print("I'll ask to the chef") | |
add_item = "hamburger" | |
# new_menu use string addition to add add_item to menu | |
new_menu = "salad, pasta, sandwich, hamburger, pizza, drinks, dessert" | |
# print the new_menu | |
print ("The new menu is the following: ", new_menu) |
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
# Create Allergy check code | |
# then PASTE THIS CODE into edX | |
# [ ] get input for input_test variable | |
food_eaten = input ("What kind of food have you been eaten in the past 24 hours, sir ? ") | |
print (food_eaten.lower()) | |
# [ ] print "True" message if "dairy" is in the input or False message if not | |
print ("It is," ,"dairy" in food_eaten.lower(), "that in your eaten food: ", food_eaten.lower(),"there is dairy") | |
# [ ] print True message if "nuts" is in the input or False if not | |
print ("It is," ,"nuts" in food_eaten.lower(), "that in your eaten food:", food_eaten.lower(),"there is nuts") | |
# [ ] Challenge: Check if "seafood" is in the input - print message | |
print ("It is," ,"seafood" in food_eaten.lower(), "that in your eaten food:", food_eaten.lower(),"there is seafood") | |
# [ ] Challenge: Check if "chocolate" is in the input - print message | |
print ("It is," ,"chocolate" in food_eaten.lower(), "that in your eaten food:", food_eaten.lower(),"there is chocolate") | |
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
def make_doctor ( name ): | |
full_name = input ("") | |
return full_name | |
docname = make_doctor("") | |
docsurname = make_doctor ("") | |
print ("Your Doctor name is " + docname + docsurname) | |
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
# [ ] create, call and test fishstore() function | |
def fish_store ( fish , price ): | |
fish_price = " Today fish is" + fish + " cost $" + price | |
return fish_price | |
today_market = fish_store (input ("What fish?") , input ("What price?")) | |
print (today_market) |
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
# [ ] create an if/else statement that tests if y is greater than or equal x + x | |
# [ ] print output: "y greater than or equal x + x is" True/False ...or a similar output | |
x = 3 | |
y = x + 1 | |
if y >= x +x: | |
print ("y greater than or equal x + x is" , y >= x +x ) | |
else: | |
print("y lower than or equal x + x is", y <= x +x ) |
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
#define the variable | |
variable = 21 | |
#define the question with input in order to have a result | |
input ("What is 8 + 13? : ") | |
#define the input as equal to the varialbe to have an if else stataement | |
if input == variable: | |
print("correct") | |
else: | |
print("incorrect") | |
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
def tf_quiz (question , correct_ans ): | |
correct_ans = input ("(T/F) Octupus have green blood: ") | |
if correct_ans == "f": | |
return "correct" | |
else: | |
return "incorrect" | |
quiz_eval = tf_quiz ( " Octupus have green blood" , " f " ) | |
print("answer is" , quiz_eval) |
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
# cast to int at input | |
mother_age = input ("How old is your mother (integer): ") | |
father_age= input ("How old is your father (interger): ") | |
if mother_age.isdigit() and father_age.isdigit() : | |
print("Ok, family age" , int(mother_age) + int(father_age) + 1) | |
else: | |
print ("Please input number") |
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
# set values for maximum order variables | |
max_order = 50.0 | |
# set values minimum order variables | |
min_order = 0.5 | |
# set value for price variable | |
order_price = 2 | |
#get order_amount input and cast to a number | |
order_amount = input ("How much icream do you want? ") | |
#check order_amount and give message checking against | |
#over maximum | |
if float(order_amount) >= max_order: | |
print ("Sorry but we can't") | |
#under minimum | |
elif float(order_amount) <= min_order: | |
print("Sorry we do not small protion take away, maybe you would like a cone") | |
#else within maximum and minimum give message with calculated price | |
else: | |
print("The total is $" , float (order_amount) * order_price) |
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
# [ ] Say "Hello" with nested if | |
# [ ] Challenge: handle input other than y/n | |
user = input (" (Y/N)Say: 'Hello' ? ").lower() | |
if user == "n": | |
print ("Friendly Nod") | |
elif user == "y": | |
input ("Full 'Hello' ? ") | |
if input == "y": | |
print ("Hi") | |
else: | |
print("Hello") |
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
# use shirt cost (S = 6, M = 7, L = 8) | |
# to calculate and report the subtotal cost for each size | |
# to calculate and report the total cost of all shirts | |
shirt = 5 | |
type_s = 0 | |
type_m = 0 | |
type_l = 0 | |
type_s_price = 6 | |
type_m_price = 7 | |
type_l_price = 8 | |
total_shirt = 0 | |
while True: | |
type_shirt = input ("What size do you want 'small', 'medium' or large': ") | |
if type_shirt.startswith("s") : | |
type_s += 1 | |
elif type_shirt.startswith("m"): | |
type_m += 1 | |
elif type_shirt.startswith("l") : | |
type_l += 1 | |
else: | |
print("We do not have it") | |
total_shirt += 1 | |
if total_shirt >= shirt: | |
print("We do not have them any more") | |
break | |
cost_s = type_s_price * type_s | |
cost_m = type_m_price * type_m | |
cost_l = type_l_price * type_l | |
total_cost = type_s * type_s_price + type_m_price * type_m + type_l_price * type_l | |
print("Number of shirt are" , total_shirt, "Total cost is $ " , total_cost, "\nSmall size price", cost_s , "\nMedium size price", cost_m , "\nLarge size price", cost_l) | |
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
while True: | |
user = input("Input a letter or number: ") | |
print() | |
if user.isdigit(): | |
if int(user) >= 99: | |
print("It is a Big Number") | |
break | |
elif int(user) <= 99: | |
print("It is a Small Number") | |
break | |
elif user.isalpha (): | |
print("It is all alphabetical") | |
break | |
else: | |
print("Wow, is not a number or a letter!") | |
break |
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
def str_analysis(io): | |
io = input("Input a letter or number: ") | |
return (io) | |
while True: | |
user = input("Input a letter or number: ") | |
print() | |
if user.isdigit(): | |
if int(user) >= 99: | |
print("It is a Big Number") | |
elif int(user) <= 99: | |
print("It is a Small Number") | |
elif user.isalpha (): | |
print("It is all alphabetical") | |
else: | |
print("Wow, is not a number or a letter!") | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment