Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

TASK 1: Python – Print exercises

20 April 2025 at 02:26

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

8.How do you print the string C:\Users\Name without escaping the backslashes?
Ans: you can also use a literal backslash "\" when using Concat or Try with 'r' to treat backslashes as literal characters

Image description

9.How do you print the result of the expression 5 + 3?

Image description

10.How do you print the strings “Hello” and “world” separated by a hyphen -?

Image description

11.How do you print the string “Hello” followed by a space, and then print “world!” on the same line?

Image description

12.How do you print the value of a boolean variable is_active which is set to True?

Image description

13.How do you print the string “Hello ” three times in a row?

Image description

14.How do you print the sentence The temperature is 22.5 degrees Celsius. using the variable temperature?

Image description

15.How do you print name, age, and city using the .format() method in the format “Name: …, Age: …, City: …”?

Image description

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?
Ans: pi is the variable & .2f formats it as a floating-point number with 2 digits after the decimal

Image description

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?

Image description

PRINT function in python

13 July 2024 at 06:48

13-07-2024

PRINT() function

print() function is a function that allows us to output to the screen

The print() function has three different uses;

  1. Single quotes (' ')
  2. Double quotes (" ")
  3. Three quotes (“”” “””)-----------for multi line

we can use anyone type quote, cannot use different quote in same line

print()---------------------------#create empty line
print("jothilingam")--------------#string should print with""
print(5)------------------------#number can print without ""
print("jo""jo")--------------print without space
print("jo"+"jo")--------------print without space
answer    jojo
print("jo","jo")--------------print with space
answer     jo jo

print with f-strings

name = "jothi"
print(f"Hello {name}")
# Output : Hello jothi

newline escape character \n

print("jo\nthi")
jo
thi

Parameters of the print() Function:

sepparameter

print("jo","jo",sep="_")...................sep="" is default
answer    jo_jo
print("jo", "lingam", sep='thi')
answer     jothilingam

endparameter

print("jothi",end="lingam")
answer  jothilingam
print("jothi",end="")----------------without space
print("lingam")
answer  jothilingam
print("jothi",end=" ")----------------with space
print("lingam")
answer  jothi lingam

* parameter

print(*"jothilingam")
answer    j o t h i l i n g a m

fileand flushparameters, since these parameters are the parameters that allow us to process the files

Task 1: print exercises

13 July 2024 at 05:14
  1. How do you print the string “Hello, world!” to the screen?

print("hello" , "world!")

  1. How do you print the value of a variable name which is set to “Syed Jafer” or Your name?

name = "syed Jafer"
print (name)

How do you print the variables name, age, and city with labels “Name:”, “Age:”, and “City:”?

print ( "name:" , name , "age:" , age , "city:" , city )

How do you use an f-string to print name, age, and city in the format “Name: …, Age: …, City: …”?

print(f" name: {name} , age: {age} , city: {city}")

How do you concatenate and print the strings greeting (“Hello”) and target (“world”) with a space between them?

print("hello " + "world")

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

print("line1\nline2\nline3")

How do you print the string He said, "Hello, world!" including the double quotes?

print (' "hello , world!" ')

How do you print the string C:\Users\Name without escaping the backslashes?

print(r"C:\users\name")

How do you print the result of the expression 5 + 3?

print (5+3)

How do you print the strings “Hello” and “world” separated by a hyphen -?

print("hello" , "world" , sep ="-")

How do you print the string “Hello” followed by a space, and then print “world!” on the same line?

print("Hello" + "world!")

How do you print the value of a boolean variable is_active which is set to True?

this = True
print(this)

How do you print the string “Hello ” three times in a row?

print("hello * 3")

How do you print the sentence The temperature is 22.5 degrees Celsius. using the variable temperature?

temperature = 22.5
print("the temperature is " + str(temperature) + " degrees celcius.")

How do you print name, age, and city using the .format() method in the format “Name: …, Age: …, City: …”?

print("name: {} , age:{} , city:{}". format(name,age,city))

Python print() funtion

8 July 2024 at 14:54

I am learned python basic concept today.
share you what i learned today with example.

The name as it is print what you entered inside print function.

Ex : print("Hello")

In additionally you can pass variables like string or integer or other data types.

anime1 = "dragon ball"
anime2 = "naruto"
Ex : print("which anime do you like ? a=", anime1, " or b=", anime2)
❌
❌