+ 1

Python3: Coding help

How to mark an input which was not given by user in if statements and make the input random?

6th Sep 2019, 9:13 AM
Ishmam
Ishmam - avatar
10 Antworten
+ 2
https://code.sololearn.com/cpuxUage9c5d/?ref=app This will work if you actually enter two numbers. But it will error if you enter a non-integer like letters etc.
6th Sep 2019, 4:40 PM
Tibor Santa
Tibor Santa - avatar
+ 2
Usually I write a try except block to handle user input, make assertions or provide default values. You can also use something like this: from random import randint number = int(input() or randint(1, 10)) print(number)
6th Sep 2019, 9:36 AM
Tibor Santa
Tibor Santa - avatar
+ 2
Tibor Santa Thank you sooooooo much for your hardwork for me!!! Finally I got my answer!!!
6th Sep 2019, 5:01 PM
Ishmam
Ishmam - avatar
+ 1
Can you give me a code example?
6th Sep 2019, 9:48 AM
Ishmam
Ishmam - avatar
+ 1
Sorry for the late reply. But I am a beginner on py3 coding. So I don't know or understand too much about coding. So can you give me a short explanation code, please?
6th Sep 2019, 3:05 PM
Ishmam
Ishmam - avatar
+ 1
A short explanation for what? Please describe precisely what you want to know.
6th Sep 2019, 3:16 PM
Tibor Santa
Tibor Santa - avatar
+ 1
For example: #i need 2 inputs X=int(input()) Y=int(input()) If X=#invalid input: #then X=random.choice(from my list) #and Y=no inputs: And same to (X) #i want a program like this
6th Sep 2019, 4:18 PM
Ishmam
Ishmam - avatar
+ 1
What is valid input? An integer number? A positive number? A number in a certain range?
6th Sep 2019, 4:28 PM
Tibor Santa
Tibor Santa - avatar
0
https://code.sololearn.com/coEFMHlSoiAG/?ref=app https://code.sololearn.com/cbhY2nyrwsbF/?ref=app https://code.sololearn.com/cAtnJQwuUpYa/?ref=app I do something like this in most of my sololearn python codes, try/except looking for ValueError and AssertionError.
6th Sep 2019, 9:57 AM
Tibor Santa
Tibor Santa - avatar
0
An integer number from my custom list.
6th Sep 2019, 4:31 PM
Ishmam
Ishmam - avatar