How to get an user confirmation in Python? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

How to get an user confirmation in Python?

I want something similar as ā€˜confirm()ā€™ in javascript. And if you also know how to give the answer with fractions and not decimals, or to convert. https://code.sololearn.com/ck5etOhJxKVi/?ref=app

5th Sep 2018, 1:04 PM
Artur Spain šŸ‡ŖšŸ‡ø
15 Respostas
+ 1
oh sorry, I wanted to say ā€˜confirm()ā€™
5th Sep 2018, 1:30 PM
Artur Spain šŸ‡ŖšŸ‡ø
+ 1
If you want answers like 3/2 instead of 1.5, you can use the fractions module. Write this at the top: from fractions import Fraction and then whichever variable you want to be written as a fraction, just put it inside Fraction(). For example, you can do str(Fraction(x1)) and str(Fraction(x2)) in your print statement. Full documentation here: https://docs.python.org/3/library/fractions.html? Regarding confirm(), I'm not sure I understand you completely. But Sololearn's python only allows us to input everything at the same time. So I don't think you can display a dialog box with Okay/Cancel option for the user.
5th Sep 2018, 2:55 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
Artur The Fraction() function will show 2.0 as 2 (and NOT 2/1), and 1.5 as 3/2. So it should be good for you!
5th Sep 2018, 3:01 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
You have a spelling mistake in line 5. Change inpit to input. When you input something, it is recognized as a string. You have to turn it into a float or int (depending on what you expect the input to be) before doing calculations. Same happens in Javascript. After getting an input, we do parseInt() before performing arithmetic. So here we can do a = float(input()) OR a = int(input()) On Sololearn, I usually omit the message "write a" inside input(). It's not displayed anyway, so it doesn't matter.
5th Sep 2018, 4:24 PM
Kishalaya Saha
Kishalaya Saha - avatar
0
I just want fractions if the number is a decimal, if is entire no
5th Sep 2018, 2:56 PM
Artur Spain šŸ‡ŖšŸ‡ø
0
thank you so much, what a pity we canā€™t use confirm :(
5th Sep 2018, 3:12 PM
Artur Spain šŸ‡ŖšŸ‡ø
0
and you know why when i use a= input(ā€œwrite aā€) happens an error?
5th Sep 2018, 3:14 PM
Artur Spain šŸ‡ŖšŸ‡ø
0
if write a number yes
5th Sep 2018, 3:57 PM
Artur Spain šŸ‡ŖšŸ‡ø
0
Post your code so we can see what's wrong.
5th Sep 2018, 3:59 PM
Kishalaya Saha
Kishalaya Saha - avatar
5th Sep 2018, 4:04 PM
Artur Spain šŸ‡ŖšŸ‡ø
0
This code runs fine! Where's the error?
5th Sep 2018, 4:10 PM
Kishalaya Saha
Kishalaya Saha - avatar
0
I didn't save, 1 second
5th Sep 2018, 4:17 PM
Artur Spain šŸ‡ŖšŸ‡ø
5th Sep 2018, 4:19 PM
Artur Spain šŸ‡ŖšŸ‡ø
0
I have corrected it but it only lets me write once and error...
5th Sep 2018, 4:36 PM
Artur Spain šŸ‡ŖšŸ‡ø
0
Input three numbers in separate lines. Like this: 1 2 3
5th Sep 2018, 4:37 PM
Kishalaya Saha
Kishalaya Saha - avatar