Chapter 5 Flashcards

1
Q

What functions can help the program to prompt us for information to make the program interactive?

A

input()

print()

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

Write the script for the result:

“Hello World, my name is Amrapali, and I am 33 years old”

A

myName= input”Please enter your name:”
myAge=input”What about your age:”
print(“Hello World, My name is”, myName, “And I am”, myAge, “years old”)

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

How can you edit the input string?

A

with the % formatter or format()

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

Briefly explain how the input function works.

A

When the print command is executed, the input function prompts the user for his/her name and then when it is entered it stores the name as a string in the variable myName. Also, it stores the age as a string in the variable myAge and later when that is entered it executes the script to display Hello World, my name is Amrapali and I am 33 years old.

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

Write the script for an interactive program using % formatter function to yield:
Hello World, My name is A and, I am 2 years old

A

userName=input(“What’s your name?:”)
userAge=input(“Hi %s, What’s your age?:”%(userName))
print(“Hello World, My name is”, userName,”,and I am”,userAge, “years old”)

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

Write the script for an interactive program using format() function to yield:
Hello World, My name is A and, I am 2 years old

A

userName=input(“What’s your name?:”)

userAge=input(“Hi {}, What’s your age?:”.format(userName))

print(“Hello World, My name is”, userName,”,and I am”,userAge, “years old”)

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

What is the print function?

A

It is used to display information to the users. It accepts zero or more expressions as arguments, separated by commas.

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

Identify arguments in the below print function

print(“Hello World, my name is”,myName,”and I am”,myAge,”years old”)

A

There are five arguments here:

  1. Hello World, my name is
  2. myName
  3. and I am
  4. myAge
  5. years old
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write the script for using the %formatter with the print function.

A

userName=”Achilles”
userAge=2
print(“Hello World, my name is %s and I am %d years old”%(userName,userAge)

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

Write the script using format()+print()

A

userName=”Achilles”
userAge=2
print(“Hello World, my name is {} and I am {} years old”.format(userName,userAge))

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

How print() function can be used to display a long message?

A

By using triple quotes.

print(“"”Hello World, My name is Calvin and I am 4 years old”””)

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

Why are triple quotes useful?

A

They improve the readability of the message.

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

Write the script for printing tabor space between two words

A

print(“Hello\tworld”)

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

Write the script for printing a new line.

A

> > > print(“Hello\nWorld”)

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

Write the script for printing “"

A

print(“\”)

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

Write the quote for printing the double quote so that the double quote doesn’t signal the end of the string.

A

print(“I am 5’3"tall”)

17
Q

Write the script for printing single quote, so that the single quote doesn’t signal the end of the string.

A

print(“The kitchen table is 12' in length”)

18
Q

What will you do when you do not want the \t interpreted as a tab? Write the script.

A

print(r”Hello\tworld”)