Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am working on this code:

print("welcome into my program")

print("you want to know the percentage then type yes")

o=input

if str(o)=='yes':

    t=input("enter the total marks\n")

    x=input("enter your marks\n")

    p=(int(x)*100)/int(t)

    print("This is your percentage =",p)

else:

    print("bye :)")

I am getting output as shown:

welcome into my program

you want to know the percentage then type yes

bye :)

When I run my code it doesn't take input from user it directly goes to the else block. Can anyone explain to me how to fix it?

1 Answer

0 votes
by (36.8k points)

You need to use the input as shown below:

print("welcome into my program")

o=input("you want to know the percentage then type yes")

if str(o)=='yes':

    t=input("enter the total marks\n")

    x=input("enter your marks\n")

    p=(int(x)*100)/int(t)

    print("This is your percentage =",p)

else:

    print("bye :)")

You will get the output as:

Welcome into my program

 you want to know the percentage then type yesyes 

enter the total marks 

700 

enter your marks 

680 

This is your percentage = 97.14285714285714

Improve your knowledge in data science from scratch using Data science online courses 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...