TASK 1: Python – Print exercises

1.How do you print the string “Hello, world!” to the screen? Ans: Using sep and end Parameters is preferred way. 2.How do you print the value of a variable name which is set to “Syed Jafer” or Your name? Ans: Note the Variable is case sensitive 3.How do you print the variables name, age, and city with labels “Name:”, “Age:”, and “City:”? Ans: Using keyword sep="," brings in , between the Variable Name and Value itself, so avoid 4.How do you use an f-string to print name, age, and city in the format “Name: …, Age: …, City: …”? Ans: To insert variables directly into the string used f-string Also, you can assign values to multiple variables in a single line as seen in 1st line 5.How do you concatenate and print the strings greeting (“Hello”) and target (“world”) with a space between them? Ans: + is used to concat the items 6.How do you print three lines of text with the strings “Line1”, “Line2”, and “Line3” on separate lines?**** 7.How do you print the string He said, "Hello, world!" including the double quotes? Ans: To print quotes inside a string, you can use either single or double quotes to enclose the string and the other type of quotes inside it.

Apr 20, 2025 - 04:15
 0
TASK 1: Python – Print exercises

1.How do you print the string “Hello, world!” to the screen?
Ans: Using sep and end Parameters is preferred way.
Image description

2.How do you print the value of a variable name which is set to “Syed Jafer” or Your name?
Ans: Note the Variable is case sensitive

Image description

3.How do you print the variables name, age, and city with labels “Name:”, “Age:”, and “City:”?
Ans: Using keyword sep="," brings in , between the Variable Name and Value itself, so avoid

Image description

4.How do you use an f-string to print name, age, and city in the format “Name: …, Age: …, City: …”?
Ans: To insert variables directly into the string used f-string
Also, you can assign values to multiple variables in a single line as seen in 1st line

Image description

5.How do you concatenate and print the strings greeting (“Hello”) and target (“world”) with a space between them?
Ans: + is used to concat the items

Image description

6.How do you print three lines of text with the strings “Line1”, “Line2”, and “Line3” on separate lines?****

Image description

7.How do you print the string He said, "Hello, world!" including the double quotes?
Ans: To print quotes inside a string, you can use either single or double quotes to enclose the string and the other type of quotes inside it.

Image description