Variables Exercises#
Question-1: Name Tag#
Use the following information to create the variables name, league, age, and height with the given values.
Create the birthyear variable using the age variable.
Design a name tag as given below.
There is a space between each asterisk in the first and last lines.
Michael Jordan played basketball in the NBA. In 2024, he is 61 years old, and his height is 1.98 meters.
Sample Output:
Question-2#
By using the variables \(x\) and \(y\) given below, print 353535
using 4 different pieces of code.
x, y = 3, 5
Question-3#
Print the statement I went to Italy in 2015.
using the country and year variables below.
country = 'Italy'
year = 2015
Warning: There is no space before the period.
Question-4: Circle#
Create a variable named r
and assign the value of \(5\) to it.
Print the area and perimeter of the circle with a radius equal to
r
.Round them to the nearest hundredth.
Hint:
Perimeter = \(2\pi r\), Area = \(\pi r^2\)
Import \(\pi\) from a module.
Output:
Perimeter: 31.42
Area : 78.54
Question-5: U-Shape#
Print the letter U using the character +
and the variable horizontal.
horizontal = 3
The vertical left and right parts of U have five
+
characters each.The variable horizontal represents the number of
+
characters with one space between them in the bottom horizontal part.
Examples
Question-6: V-Shape#
Print the following using the character *
, spaces and the variable n=5
to represent the number of *
characters in each block.
Question-7: H-Shape#
Print the following ‘H’ shapes using the characters ‘+’, ‘ ‘, ‘-’, and the variable number_dash
.
number_dash = 5
The number of ‘-’ characters in the middle line is represented by the variable ‘number_dash’.
Examples
Question-8: Receipt Generator#
The following code generates a basic store receipt. Improve its appereance by adding separators (dashes -) and formatting the price, tax, tip, and discount details to make it look more professional, similar to real receipts.
from datetime import datetime
current_date_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') # string object
restaurant_name = 'Olive Garden'
price = 100
tax = 0.08
tip = 0.15
discount = 7
tax_amount = tax*price
tip_amount = tip*price
total = price + tax_amount + tip_amount - discount
print(restaurant_name)
print(current_date_time)
print('Total :', total)