+ 1

I have a problem trying to execute if statements in my calculator project

https://sololearn.com/compiler-playground/ccm2PRh16J3l/?ref=app

9th Jul 2024, 4:33 PM
TREVOR NGATHO
TREVOR NGATHO - avatar
7 Answers
+ 2
Yes, you can enter an int or float after the input so that the user input can be converted into an integer or floating-point number. You have to use the input function inside the print function and then convert that input into int or float. This will be correct.
11th Jul 2024, 2:40 PM
Chitranshi Gupta
Chitranshi Gupta - avatar
+ 3
answer=print(input("What shape is here")) Print the content of "answer". What do you observe? print() does not have a return value. Hence, "answer" will be None, no matter what you enter. input() always returns a string. So when you enter "2.3", it will be a string, not a number. You need to convert the input to a numeric value. The same 2 things apply to the other parts of your program. Also, mind that sololearn Python playground is not interactive. You need to input all values in the beginning of the program – separated by line breaks. Read the small test in the pop-up window.
9th Jul 2024, 4:39 PM
Lisa
Lisa - avatar
+ 2
def area(): import sys input = sys.stdin.read data = input().split() if not data: print("No input provided") return answer = data[0].strip().lower() if answer == "sphere": if len(data) < 2: print("Radius not provided") return r = float(data[1]) print('Your answer is:', 4 * 3.1428 * r * r * r) elif answer == "square": if len(data) < 2: print("Width not provided") return width = float(data[1]) print('Your answer is:', width * width) elif answer == "rectangle": if len(data) < 3: print("Length and/or width not provided") return length = float(data[1]) width = float(data[2]) print('Your answer is:', length * width) else: print("Unknown shape") # Call the area function area()
11th Jul 2024, 6:46 AM
Chitranshi Gupta
Chitranshi Gupta - avatar
+ 1
Yeah Lisa is correct You should not put input() inside print() Other suggestions I would like to add are Surface area for sphere is 4πr² Not 4πr³ And pi value is 3.14159... Not 3.1428 Hope it helps you ✨
9th Jul 2024, 5:49 PM
Hacker Badshah
Hacker Badshah - avatar
+ 1
Thank you for your suggestions❤️❤️But I'm still wondering how I'll get to involve the user🤔What if I put and 'int' after input inside the print😅 I mean..won't it work?
11th Jul 2024, 12:24 PM
TREVOR NGATHO
TREVOR NGATHO - avatar
+ 1
Thanks again😌
17th Jul 2024, 7:54 AM
TREVOR NGATHO
TREVOR NGATHO - avatar
0
Hacker Badshah ,Lisa thanks so much😌❤️I'm still on it I want to also add BMI and even step count😂🔥
17th Jul 2024, 7:56 AM
TREVOR NGATHO
TREVOR NGATHO - avatar