Chapter 2 Flashcards

1
Q

Write a program that displays the next message:
Hello Python world!

A

print(“Hello Python World!”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Store the message “Hello Python World!” in a variable and then print it.

A

message = “Hello Python World!”
print(message)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Store a name in a variable and then print the name in lowercase, uppercase and titlecase.

A

name = “simona dop”
print(name.upper())
print(name.lower())
print(name.title())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Store a person’s name in a variable, and then print that person’s name in lowercase, uppercase, and titlecase.

A

person_name = “Simona Dop”
print(person_name.upper())
print(person_name.lower())
print(person_name.title())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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?”

A

person_name = “Simona Dop”
print(“Hello, “ + person_name + “!” + “ “ + “Would you like to learn some Python?”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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.”

A

message = “‘A person who never made a mistake never tried anything new.’”
print(“Albert Einstein once said, “ + message)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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.

A

famous_person = “Albert Einstein”
message = “‘A person who never made a mistake never tried anything new.’”
print(famous_person + “once said, “ + message)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Store a person’s name, and include some whitespace characters at the beginning and end of the name.

A

my_name = “ Simona Dop “
print(my_name)
print(my_name.lstrip())
print(my_name.rstrip())
print(my_name.strip)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

list_of_names = “Names: Jonathan Mary Jim Annabelle”
print(list_of_names)
print(“Names:\n\tJonathan\n\tMary\n\tJim\n\tAnnabelle”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write addition, substraction, multiplication, and division operations that each result in the number 8.

A

print(4+4)
print(4*2)
print(16/2)
print(18-10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Store your favorite number in a variable. Then, using that variable, create a message that reveals your favorite number. Print that message.

A

favorite_number = 22
print(“My favorite number is “ + str(favorite_number) + “.”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly