❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdayGanesh Balaraman

Task 2 - Constants and variables

15 July 2024 at 10:31

Create a variable named name and assign your name to it. Then print the value of the variable.

name = "ganesh"
print(name)

Create a variable age and assign your age to it. Later, reassign the variable with a new value and print the new value.

age = 36
age = 37
print(age)

Assign the values 5, 10, and 15 to three variables a, b, and c in a single line. Print their values.

a , b , c = 5 , 10 , 15
print(a , b , c)

Swap the values of two variables x and y without using a third variable. Print their values before and after swapping.

x , y = 1 , 2
print(x , y)
x , y = 2, 1
print(x , y )

Define constants PI with appropriate values and print them.

PI = 3.14
print(PI)

Write a program that calculates the area of a circle using the constant PI and a variable radius. Print the area.

PI = 3.14
r = 5
a = pi * r * r
print(a)
79.5

Define constants for the length and width of a rectangle. Calculate and print the area.
Define a constant for Ο€ (pi) and a variable for the radius. Calculate and print the circumference of the circle.

LENGTH = 60
WIDTH = 20
a = LENGTH * WIDTH
print(a)
1200

PI = 3.14
r = 8
circumference = 2 * pi * r
circumference = 2 * PI * r
print(circumference)
50.24

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))

❌
❌