Chapter 2 Flashcards
Write a program that displays the next message:
Hello Python world!
print(“Hello Python World!”)
Store the message “Hello Python World!” in a variable and then print it.
message = “Hello Python World!”
print(message)
Store a name in a variable and then print the name in lowercase, uppercase and titlecase.
name = “simona dop”
print(name.upper())
print(name.lower())
print(name.title())
Store a person’s name in a variable, and then print that person’s name in lowercase, uppercase, and titlecase.
person_name = “Simona Dop”
print(person_name.upper())
print(person_name.lower())
print(person_name.title())
Store a person’s name in a variable, and print a message to that person. Your message should be simple, such as, “Hello Eric, would you like to learn some Python?”
person_name = “Simona Dop”
print(“Hello, “ + person_name + “!” + “ “ + “Would you like to learn some Python?”)
Find a quote from a famous person. Print that quote and the name of its author. Your output should look something like the following, including the quotation marks:
Albert Einstein once said, “A person who never made a mistake never tried anything new.”
message = “‘A person who never made a mistake never tried anything new.’”
print(“Albert Einstein once said, “ + message)
Find a quote from a famous person. Print that quote and the name of its author. Your output should look something like the following, including the quotation marks. You MUST store the famous person’s name in a variable called famous_person. Then compose your message and store it in a new variable called message.
famous_person = “Albert Einstein”
message = “‘A person who never made a mistake never tried anything new.’”
print(famous_person + “once said, “ + message)
Store a person’s name, and include some whitespace characters at the beginning and end of the name.
my_name = “ Simona Dop “
print(my_name)
print(my_name.lstrip())
print(my_name.rstrip())
print(my_name.strip)
Write a list of names and then make sure the result looks like the following (using tab function and newline):
Names:
Jonathan
Mary
Jim
Annabelle
list_of_names = “Names: Jonathan Mary Jim Annabelle”
print(list_of_names)
print(“Names:\n\tJonathan\n\tMary\n\tJim\n\tAnnabelle”)
Write addition, substraction, multiplication, and division operations that each result in the number 8.
print(4+4)
print(4*2)
print(16/2)
print(18-10)
Store your favorite number in a variable. Then, using that variable, create a message that reveals your favorite number. Print that message.
favorite_number = 22
print(“My favorite number is “ + str(favorite_number) + “.”)