Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
Goeduhub's Online Courses @ Udemy in Just INR 570/-
Online Training - Youtube Live Class Link
13 like 0 dislike
25k views
in Python Programming by Goeduhub's Expert (2.2k points)
edited by

Assignment/Task 1

Hint: Python If Condition

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

 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"

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

 Hint: Loop Questions

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

4.  Write a program that prints following shape

*

* *

* * *

* * * *

* * * * *

* * * *

* * *

* *

*

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

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

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

8.  Your Marks for five Test(test1 to test5) looks like this,

marks_list = [65, 75, 2100, 95, 83]

Write a program that asks you to enter marks and program should tell you in which test that marks occurred. If marks is not found then it should print that as well.

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 360/- || For International Students- $9.99/-

S.No.

Course Name

 Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

3.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon
    More Courses

6 Answers

3 like 0 dislike
by Goeduhub's Expert (2.2k points)
selected by
 
Best answer

Q.1 i)

Colors = ["Yellow","Green","White","Black"]

Fruits = ["Apple","Papaya","Mango","Orange"]

Animals = ["Tiger","Lion","Deer","Zebra"]

n = input("Enter color, fruit or animal name : ")

if n in Colors:

    print(n,"is a Color")

elif n in Fruits:

    print(n,"is a Fruit")

elif n in Animals:

    print(n,"is an Animal")

else:

    print("Sorry! not in any category")

ii) 

m = input("Enter a name :")

n = input("Enter a name :")

if m in Colors and n in Colors:

    print("Both are Colors")

elif m in Fruits and n in Fruits:

    print("Both are Fruits")

elif m in Animals and n in Animals:

    print("Both are Animals")

else:

    print("They don't belong to same category")

 Q. 2

score=float(input("Enter your score: "))

if score > 60:

   print(f"{score} is good mark")

elif score < 40:

   print(f"{score} is low mark")

else:

  print(f"{score} is normal mark")

Q.3

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

count = 0

for i in result:

  if i == "Pass":

    count += 1

print(f'You passed {count} times') 

Q. 4 

rows = 5

for i in range(0,rows):

  for j in range(0,i+1):

    print("*",end = " ")

  print()

for i in range(rows+1,0,-1):

  for j in range(1,i-1):

    print("*",end = " ")

  print()

Q. 5

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

Q. 6

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

Q. 7

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

Q. 8 

test_list = ["Test1","Test2","Test3","Test4","Test5"]
marks_list = [657521009583]
mark= int(input("Enter the mark: "))
test=-1
for i in range(len(marks_list)):
    if mark == marks_list[i]:
        test = i
        break

if test != -1:
    print(f'You got {mark} in {test_list[test]}')
else:
    print(f'Oops!, I found that You have entered the wrong mark {mark}. Please provide the correct marks')
2 like 3 dislike
by (114 points)

Q.1) i)

n = input("Enter color, fruit or animal name : ")

if n in Colors:

    print(n,"is a Color")

elif n in Fruits:

    print(n,"is a Fruit")

elif n in Animals:

    print(n,"is an Animal")

ii)

m = input("Enter a name :")

n = input("Enter a name :")

if m and n in Colors:

    print("Both are Colors")

elif m and n in Fruits:

    print("Both are Fruits")

elif m and n in Animals:

    print("Both are Animals")

else:

    print("They don't belong to same category")

Q.2)

score = int(input("Enter your score :"))

if score < 40 :

    print("Score is low")

elif score > 60 :

    print("Score is good")

else :

    print("Score is normal")

Q.3)

count = 0

for x in result :

    if x == "Pass" :

        count += 1

print("You passed", count, "times")

Q.4)

rows = 5

for i in range(0,rows):

    for j in range(0,i+1):

        print("*",end = " ")

    print(" ")

for i in range(rows+1,0,-1):

    for j in range(1,i-1):

        print("*",end = " ")

    print(" ")

Q.5)

flag = 0

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

            flag =1

            break

        elif n == "NO":

            continue

if flag == 0:

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

Q.6)

for i in range(1500,2701):

    if i%7 == 0 and i%5 == 0:

        print(i)

Q.7)

for x in range(10,21):

    if x%2==1:

        print(x**2)

Q.8)

n = int(input("Enter marks :"))

if n not in marks_list :

    print("Marks not in list")

else:

    for x in marks_list:

        if x == n:

            print("You got",n,"marks in","test",x)

0 like 1 dislike
by (108 points)
3q. After appearing in exam 10 times you got this result,

Code:-

Result= ["Pass","Fail","Fail","Pass","Fail","Pass","Pass","Fail","Fail","Fail"]

Count=0

For i  in Result:

If (i == "pass"):

Count=count+1

Print(count)

1Q. We are having 3 list like this

Code:-

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

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

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

a = input() # user input at run time

If a in Colours:

    Print(Colours)

elif  a in Animals:

    Print(Animals)

else:

Print(Fruits)
0 like 1 dislike
by (138 points)
Answer for first question:
1.Colors = ["Yellow","Green","White","Black"]
Fruits=["Apple","Papaya","Mango","Orange"]
Animals=["Tiger","Lion","Deer","Zebra"]
# ANSWER FOR (i)
user=input("Enter the  Color/Fruit/Animal name :").title().strip()
if user in Colors:
   print(f"{user} is Belongs to the category of Colors")
elif user in Fruits:
   print(f"{user} is Belongs to the category of Fruits")
else:
   print(f"{user} is Belongs to the category of Animals")
# ANSWER FOR (ii)
user_1 = input("Enter your city: ").title()
user_2 = input("Enter your city: ").title()
if user_1 == user_2:
   print(f"{user_1} {user_2} You both are living in same city! ")
else:
   print(f"{user_1} {user_2} You both are not living in same city! ")
2.  Write a python program that can tell you if your grade score good or not . Good Score range is 40 to 60.
   score=int(input("Enter your score: "))
if score > 60:
   print(f"{score} is good mark")
else:
   print(f"{score} is low mark")

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.

ANSWER:

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

  for Pass in result:

   print(result)

Your Marks for five Test(test1 to test5) looks like this,

marks_list = [65, 75, 2100, 95, 83]

Write a program that asks you to enter marks and program should tell you in which test that marks occurred. If marks is not found then it should print that as well.

#ANSWER:

marks_list = [657521009583]

print(marks_list)
mark= int(input("Enter the mark: "))
Test = marks_list.index(mark) +1
if mark in marks_list:
  print(f"The mark {mark} is obtained in the test {Test} ")
else:
  print("Oops!, I found that You've entered the wrong mark. Please provide the correct marks")
0 like 0 dislike
by (110 points)
C=['Yellow','Green','White','Black']
F=['Apple','Papaya','Mango','Orange']
A=['Tiger','Lion','Deer','Zebra']
s=input("enter a color/fruit/animal name")
if s in C:
  print("the "+s+"belongs to color list")
elif s in F:
  print("the "+s+"belongs to fruit  list")
elif s in A:
  print("the "+s+"belongs to animal list")
c=['mumbai','pune','bangalore','hyderabad']
i=input("enter a city name:")
k=input("enter a city name:")
if k in c:
  if i in c:
    print("they belong to the same country")
else:
  print("they dont belong to the same country")  
k=int(input("enter your score:"))
if k>40 and k<60:
  print("your score is low")
elif k>60:
  print("your score is good")
1 like 0 dislike
by (112 points)

1. i.

S = input("Enter a color/fruit/animal name: ")
if S in Colors:
  print(f'{S} is in Colors')
elif S in Fruits:
  print(f'{S} is in Fruits')
else:
  print(f'{S} is in Animals')
ii.
S = input("Enter a color/fruit/animal name: ")
 
S1 = input("Enter a color/fruit/animal name: ")
 
if S in Colors and S1 in Colors:
  print(f'{S} and {S1} is in Colors')
elif S in Fruits and S1 in Fruits:
  print(f'{S} and {S1} is in Fruits')
elif S in Animals and S1 in Animals:
  print(f'{S} and {S1} is in Animals')
else:
  print("They don't belong to same category")
2.
Grade = int(input("Enter your grade: "))
if 40 < Grade <= 60:
  print("Your score is low")
elif Grade > 60:
  print("Your score is Good")
else:
  print("Your score is normal")
3.
count = 0
for i in result:
  if i == "Pass":
    count += 1
print(f'You passed {count} times')
4.
for i in range(6):
  for j in range(i):
    print("*",end=" ")
  print()
for i in range(5,0,-1):
  for j in range(i):
    print("*",end = " ")
  print()
5.
distance = 50
for i in range(10,distance+1,10):
  print("Are you tierd")
  S = input()
  if S == "Yes":
    print("you didn't finished the race")
    break
  if i == 50:
    print("congrats")
  
6.
for i in range(1500,2701):
    if i%7==0 and i%5==0:
        print(i)
7.
for i in range(10,20):
  if i%2 != 0:
    print(i**0.5)
8.
Marks = int(input("Enter marks: "))
if Marks in marks_list:
  print("Test",marks_list.index(Marks))
else:
  print("Not found")

3.3k questions

7.1k answers

394 comments

4.6k users

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...