Assignments
Assignments
1. Create a variable called break and assign it a value 5. See what happens and find
out the reason behind the behavior that you see.
2. Create two variables. One to store your birth year and another one to store
current year. Now calculate your age using these two variables
3. Store your first, middle and last name in three different variables and then print
your full name using these variables
4. Answer which of these are invalid variable names:
_nation
1record
record1
record_one
record-one
record^one
continue
# Exercise Numbers
# 1. You have a football field that is 92 meter long and 48.8 meter wide. Find out
total
length=92
width=48.8
area=length*width
# Find out using python, how many dollars is the shopkeeper going to give you
back?
num_packets=9
cost_per_packet=1.49
total_cost=num_packets*cost_per_packet
money_paid=20
cash_back=money_paid-total_cost
# 3. You want to replace tiles in your bathroom which is exactly square and 5.5 feet
# is its length. If tiles cost 500 rs per square feet, how much will be the total
# cost to replace all tiles. Calculate and print the cost using python
length=5.5
cost=area*500
num=17
1. Create 3 variables to store street, city and country, now create address variable to
store entire address. Use two ways of creating this variable, one using + operator
and the other using f-string.
Now Print the address in such a way that the street, city and country prints in a
separate line
2. Create a variable to store the string "Earth revolves around the sun"
3. Create two variables to store how many fruits and vegetables you eat in a day.
Now Print "I eat x veggies and y fruits daily" where x and y presents vegetables
and fruits that you eat everyday. Use python f string for this.
4. I have a string variable called s='maine 200 banana khaye'. This of course is a
Replace incorrect words in original strong with new ones and print the new string.
Also try to do this in one line.
# 1. Let us say your expense for every month are listed below,
# 1. January - 2200
# 2. February - 2350
# 3. March - 2600
# 4. April - 2130
# 5. May - 2190
# Create a list to store these monthly expenses and using that find out,
# 2. Find out your total expense in first quarter (first three months) of the year.
# 4. June month just finished and your expense is 1980 dollar. Add this item to our
monthly expense list
# based on this
exp = [2200,2350,2600,2130,2190]
print("In feb this much extra was spent compared to jan:",exp[1]-exp[0]) # 150
# 2. Find out your total expense in first quarter (first three months) of the year
# 4. June month just finished and your expense is 1980 dollar. Add this item to our
monthly expense list
exp.append(1980)
print("Expenses at the end of June:",exp) # [2200, 2350, 2600, 2130, 2190, 1980]
# based on this
exp[3] = exp[3] - 200
print("Expenses after 200$ return in April:",exp) # [2200, 2350, 2600, 1930, 2190,
1980]
print(len(heros))
heros.append('black panther')
print(heros)
# 3. You realize that you need to add 'black panther' after 'hulk',
# so remove it from the list first and then add it after 'hulk'
heros.remove('black panther')
heros.insert(3,'black panther')
print(heros)
# 4. Now you don't like thor and hulk because they get angry easily :)
# So you want to remove thor and hulk from list and replace them with doctor
strange (because he is cool).
heros[1:3]=['doctor strange']
print(heros)
heros.sort()
print(heros)
```
pakistan = ["lahore","karachi","islamabad"]
```
1. Write a program that asks user to enter a city name and it should tell which
country the city belongs to
2. Write a program that asks user to enter two cities and it tells you if they both
are in same country or not. For example if I enter mumbai and chennai, it will print
"Both cities are in India" but if I enter mumbai and dhaka it should print "They
don't belong to same country"
2. Write a python program that can tell you if your sugar is normal or not. Normal
fasting level sugar range is 80 to 100.
3. If it is above 100 then print that it is high otherwise print that it is normal