Python If Condition, ASSIGNMENT - 1 , GO_STP_8113

 GO_STP_8113

Goeduhub Technologies

Data Science and Machine Learning with Python Online Training

#OnlineSummerTraining  #machinelearning #pythonprogramming #python #goeduhub

Task Link

1. We are having 3 list like this

Colors = [“Yellow”,”Green”,”White”,”Black”]

Fruits=[“Apple”,”Papaya”,”Mango”,”Orange”]

Animals=[“Tiger”,”Lion”,”Deer”,”Zebra”]

(i): Write a program that asks user to enter a Color/Fruit/Animal name and it should tell which category belongs to , like its is a fruit or color or Animal

Program:

Colors = ["Yellow","Green","White","Black"]
Fruits=["Apple","Papaya","Mango","Orange"]
Animals=["Tiger","Lion","Deer","Zebra"]

n = input("Enter a Color/Fruit/Animal name ")
if n in Colors:
    print(n,"belongs to colors category")
elif n in Fruits:
    print(n,"belongs to fruits category")
elif n in Animals:
    print(n,"belongs to animals category")
else:
    print("No category is available in lists")

Output:
Enter a Color/Fruit/Animal name Lion Lion belongs to animals category

ii. Write a program that asks user to enter two items and it tells you if they both are in same category or not. For example if I enter yellow and Black, it will print "Both are colors" but if I enter yellow and Tiger it should print "They don't belong to same category"

Program:

Colors = ["Yellow","Green","White","Black"]
Fruits=["Apple","Papaya","Mango","Orange"]
Animals=["Tiger","Lion","Deer","Zebra"]

n = input("Enter item one ")
m = input("Enter item two ")
if n and m in Colors:
  print(n,"and",m,"both are Colors")
elif n and m in Fruits:
  print(n,"and",m,"both are Fruits")
elif n and m in Animals:
  print(n,"and",m,"both are Animals")
else:
   print("They don't belong to same category")

Output:
Enter item one Apple Enter item two Mango Apple and Mango both are Fruits

2.  Write a python program that can tell you if your grade score good or not . Normal Score range is 40 to 60.

  i. Ask user to enter his score.

  ii. If it is below 40 to 60 range then print that score is low

  iii. If it is above 60 then print that it is good otherwise print that it is normal


Program:

n = int(input("Enter your score: "))
if n<40:
  print(n,"score is low")
elif n>60:
  print(n,"score is good")
else:
  print("Normal score")

Output:
Enter your score: 98 98 score is good


3.  After appearing in exam 10 times you got this result,

result = ["Pass","Fail","Fail","Pass","Fail","Pass","Pass","Fail","Fail","Fail"]

Using for loop figure out how many times you got Pass

Program:

result = ["Pass","Fail","Fail","Pass","Fail","Pass","Pass","Fail","Fail","Fail"]
j=0
k=0
for i in result: 
 if i=="Pass":
    j=j+1
 else:
    k=k+1
   
print("Passed",j,"times")
print("Failed",k,"times")

Output:
Passed 4 times Failed 6 times

4.  Write a program that prints following shape

*

* *

* * *

* * * *

* * * * *

* * * *

* * *

* *

*

Program:

for i in range(1,6):
  print(" * " * i)
  print(" ")
for i in range(4,0,-1):
  print(" * " * i)
  print(" ")

Output:
* * * * * * * * * * * * * * * * * * * * * * * * *


5.   Lets say you are running a 50 km race. Write a program that,

  • Upon completing each 10 km asks you "are you tired?"
  • If you reply "yes" then it should break and print "you didn't finish the race"
  •  If you reply "no" then it should continue and ask "are you tired" on every km
  • If you finish all 50 km then it should print congratulations message

Program:
for i in range(1,51):

  if i%10 == 0:

    n = input("Are you tired?")

    if n == "YES":

      print("You didn't finish the race")

      break

if i==50:

  print("Congratulations!! You finished the race")

else:

  print(f"congrats! You still ran {i} KM")

Output:

Are you tired?No Are you tired?Yes Are you tired?No Are you tired?No Are you tired?No Congratulations!! You finished the race


6.  Write a Python program to find those numbers which are divisible by 7 and multiple of 5, between 1500 and 2700 (both included).

Program:

for i in range(1500,2701):
  if i%7 == 0 and i%5 == 0:
    print(i)

Output:
1505 1540 1575 1610 1645 1680 1715 1750 1785 1820 1855 1890 1925 1960 1995 2030 2065 2100 2135 2170 2205 2240 2275 2310 2345 2380 2415 2450 2485 2520 2555 2590 2625 2660 2695

7.   Print square of all numbers between 10 to 20 except even numbers

Program:
for i in range(10,21):
    if i % 2 == 0:
        continue
    print(i*i)

Output:

121 169 225 289 361

8. Your Marks for five Test(test1 to test5) looks like this, marks_list = [65, 75, 2100, 95, 83]
Program:
x= float(input("Enter marks=")) marks_list = [65, 75, 2100, 95, 83] if x in marks_list: qwe = marks_list.index(x) print("You have got",x,"marks in test",qwe+1) else: print("Marks",x,"not found") Output: Enter marks=2100 You have got 2100.0 marks in test 3

Comments

Popular posts from this blog

Data Science Matplotlib Library Data Visualization, ASSIGNMENT - 6, GO_STP_8113