Exercises
1. Create 3 variables “company_name”, “f_name” and “l_name”.
Set “company_name” variable as “ayCLOgic”
Set “f_name” variable as “joHN” . Please keep this mix cases
Set “l_name” variable as “WaShington”
print “Welcome to AYCLOGIC, John Washington” using the 3 variables above.
Please use “f” Python formatter when you combine strings. If you don’t know how to do this, please review page 21 from the text book.
2. Get input from shell “What is your name: ”
print to the shell “<input from shell> is a very cool name.”
For example
What is your name: gAmAs gAmAs is a very cool name.
If you don’t know how to do this, please review page 114 from the Text book.
3. Get input from shell: “What is your favorite food: ”
if the user enter “burger”, then the program will print
“Burger is my favorite food.”
otherwise the program will print
“<user input> is not a yummy food.
If you don’t know how to do this, please review page 79 and page 114 from the text book.
Example 1
What is your favorite food: burger Burger is my favorite food
Example 2
What is your favorite food: sPinAch Spinach is not a yummy food.
4. Change above program so when you enter either
burger, hot dog or chicken nugget, it will say
<name of food> is my favorite food.
Otherwise it will say
<name of food> is not a yummy food
Example 1
What is your favorite food: burger Burger is my favorite food
Example 2
What is your favorite food: hot dog Hot dog is my favorite food
Example 3
What is your favorite food: spinach Spinach is not a yummy food
5. Create a list of monsters: “dragon”, “phoenix”, “minotaur”, “hydra”
a. using the list print “DRAGON is a powerful monster”. Get the first element of the list and combine with ” is a powerful monster” String.
b. using the list print “Hydra is a monster with many heads”. Get the last element of the list and combine with ” is a monster with many heads” String.
If you don’t know how to do this, please look at page 34 from the text book.
6. Using list above, use for loop to print each element in the list
in uppercase.
For example
DRAGON PHOENIX MINOTAUR HYDRA
7. Using list above, use for loop to print each element in the list.
But if it is phoenix, print “Phoenix is a beautiful magnificent creature” . Hint you have to use an IF ELSE statement inside the for loop.
For example
dragon Phoenix is a beautiful magnificent creature. minotaur hydra
8. Using for loop, print “Hooray” 3 times.
9. Create a program that will continuously asking user “What is the biggest animal on earth: ” . The program will continuously asking this question until the user answer “blue whale”.
For example
What is the biggest animal on earth: elephant ELEPHANT is a wrong answer What is the biggest animal on earth: tiger TIGER is a wrong answer What is the biggest animal on earth: blue whale BLUE WHALE is the correct answer
10. Ask user for his age and if user’s age is bigger than or equal to 60 say “<age> years old!! WOW that is old dude”. Otherwise, the program will say “<age> years old is young”.
example 1
How old are you: 59 59 years old is young.
Example 2
How old are you: 60 60 years old!! WOW that is old dude
Example 2
How old are you: 65 65 years old!! WOW that is old dude