Python Question - Please Respond

Ok so this code looks right (atleast to me) and kinda is but for example;
if i write 5 and 5 and say they equal 1 it prints correct? Whats so wrong about this code?

ques1 = input("Type a number: ")
ques2 = input("Type another number: ")
ques3 = input("What is the 1st number you typed + the 2nd?: " )

if int(ques1) * int(ques2):
print “Correct”
else:
print “Wrong”

Hello @prxtham,

Can you explain what are you trying to do ?
I think you’re trying to make a program that takes two numbers and compares them?
Then if they’re equal then print Correct otherwise Wrong ?

2 Likes

I’m trying to make a program that takes 2 numbers from the user and it asks the user whats the answer if you multiply them.
eg,
Type a number (5)
Type another number (5)
What is 5 x 5?
(you say 25 the program says Correct)
(you say 24 the program says Wrong)

My friend wrote it in python in like 10seconds in that same format, I dont know how it doesnt work. :frowning:

The procedure is okay (in your code apart from language, It’s a bit vague).
The problem exists in if-clause, Where we have to test if multiplication of two numbers is equal to answer provided by the user.

Hint*

first_number * second_number == answer_provided

Right now, Your if clause test always evaluates down to Truethy value(unless one of the number is 0) so It always prints Correct

2 Likes

ok 2 questions. can you explain how this code works
a = input("Type a number: ")
b = input("Type another number: ")
c = input("What is the 1st number you typed + the 2nd?: " )
d = int(a) + int(b)

if str(d) == str(c):
print “Correct”
else:
print “Wrong”

and lastly where it says
c = input("What is the 1st number you typed + the 2nd?: " )
how do i make it so it tells the program "What is (1st input goes here) + (2nd input goes here) "

I’ll give you procedure…

1.Take first number as input.
2.Take second number as input.
3.Take probable guess from user (say multiplication or addition of two numbers)
4.Convert inputs into number using int() function (if user has input number but we know that input() gets it as string)
5.Test if user guess and correct answer matches or not.
6.If yes print Correct or print Wrong

Tho in your last code, You’re comparing addition of two numbers with probable guess of user.
In first code, It was multiplication (as you mentioned ).

2 Likes