+ 1
Python3: Coding help
How to mark an input which was not given by user in if statements and make the input random?
10 Answers
+ 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.
+ 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)
+ 2
Tibor Santa Thank you sooooooo much for your hardwork for me!!!
Finally I got my answer!!!
+ 1
Can you give me a code example?
+ 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?
+ 1
A short explanation for what? Please describe precisely what you want to know.
+ 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
+ 1
What is valid input? An integer number? A positive number? A number in a certain range?
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.
0
An integer number from my custom list.