Task-1: Python-Print Exercises
Published: 2024-07-10 09:16:43

# 1. How do you print the string “Hello, world!” to the screen?
print('Question-1')
print(" Hello, world!")
print("\n")

# 2. How do you print the value of a variable name which is set to “Syed Jafer” or Your name?
print('Question-2')
value = "Syed Jafer"
print("Name : ",value)
print("\n")

# 3. How do you print the variables name, age, and city with labels “Name:”, “Age:”, and “City:”?
print('Question-3')
name = "Syed Jafer"
age = 16
city = "Trichy"
print("Name: ",name,"\tAge: ",age,"\tCity: ",city)
print("\n")

# 4. How do you use an f-string to print name, age, and city in the format “Name: …, Age: …, City: …”?
print('Question-4')
name = "Syed Jafer"
age = 16
city = "Trichy"
print("Name: ",name,"Age : ",age," Ciity : ",city)
print("\n")

# 5. How do you concatenate and print the strings greeting (“Hello”) and target (“world”) with a space between them?
print('Question-5')
print("Hello "+"World")

# 6. How do you print three lines of text with the strings “Line1”, “Line2”, and “Line3” on separate lines?
print('Question-6')
for i in range(3):
    print("Line",i+1 )
print("\n")

# 7. How do you print the string He said, "Hello, world!" including the double quotes?
print('Question-7')
print('"Hello! World"')
print("\n")

# 8. How do you print the string C:\Users\Name without escaping the backslashes?
print('Question-8')
print("C:","Users","Name",sep="\\")
print("\n")

# 9. How do you print the result of the expression 5 + 3?
print('Question-9')
print("5 + 3")
print(5+3)

print("\n")
# 10. How do you print the strings “Hello” and “world” separated by a hyphen -?
print('Question-10')
print("Hello","World",sep="-")
print("\n")

# 11. How do you print the string “Hello” followed by a space, and then print “world!” on the same line?
print('Question-11')
print("Hello World!")
print("Hello","World!")
print("\n")

# 12. How do you print the value of a boolean variable is_active which is set to True?
print('Question-12')
is_active = True
print(is_active)
print("\n")

# 13. How do you print the string “Hello ” three times in a row?
print('Question-13')
print("Hello\n"*3)
print("\n")

# 14. How do you print the sentence The temperature is 22.5 degrees Celsius. using the variable temperature?
print('Question-14')
temperature = 22.5
print("Temperature is ",temperature,"degrees celsius")
print("\n")

# 15. How do you print name, age, and city using the .format() method in the format “Name: …, Age: …, City: …”?
print('Question-15')
name = "Syed Jafer"
age = 16
city = "Trichy"
print("Name: {},Age: {},Ciity: {}".format(name,age,city))
print("\n")

# 16. How do you print the value of pi (3.14159) rounded to two decimal places in the format The value of pi is approximately 3.14?
print('Question-16')
pi = 3.14159
print("Pie : {:.2f}".format(pi))
print("Pie : {:.2f}".format(3.14159))
print(f"Pie : {pi:.2f}")
print(f"Pie : {3.14159:.2f}")
print("\n")

# 17. How do you print the words “left” and “right” with “left” left-aligned and “right” right-aligned within a width of 10 characters each?

print('Question-17')
print('{:<10}'.format("left"))
print('{:>10}'.format("right"))

print('{:<10}'.format("left"),'{:>10}'.format("right"))
print("\n")


Output:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e98bw42sau9azu97rtte.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0nn54hzj5mgcgzqezqe.png)