1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Andre45 [30]
4 years ago
13

How do you identify certain input answers in python?

Computers and Technology
1 answer:
Papessa [141]4 years ago
5 0
If you would like to check the value on an input, you will have to handle the ValueError that may occur if you try to convert the input.

- If you want the input to be a string, then that's simple, because input is already a string :)

- If you want the input to be an integer, a float, or whatever else, of course you would have to convert your string input to whatever you require. For example:

If you try
age = int(input('Enter your age: '))
And the user enters something like 5, then that's fine and will convert no problem.
However, if you tried to enter 1.5, or 'hello' or something that is NOT an integer, you will notice it generates something called a "ValueError", and the program will cease to parse.
This is what I mean by handling the error. We make our program 'handle' the error and do something else if it occurs, so that it doesn't crash our program and it can continue parsing.
This can be done by using the keywords "try" and "except"

try is a block of code that you expect an error (called an exception in other languages, hence the keyword "except"), and the except catches certain type of errors. In the exam below, we have a loop that continuously asks the user for their age until the value is valid:

<span>age = <span>None
</span>while not isinstance(age, int):
    try:
        age = int(input('Enter your age: '))
        if age < 0:
            raise <span>ValueError
</span>    except ValueError:
        print('That is not a valid age.')
</span>
Let me know if you have any questions :)

 
You might be interested in
Why is it important to be a good digital citizen? 2-3 sentences
weqwewe [10]

Answer:

It's nice to be a good digital citizen because you'll stay out of trouble. It will help make someone's day without any negativity. It helps ensure that there is no cyberbullying occuring.

6 0
3 years ago
Read 2 more answers
How to add running head and page number in word?
yaroslaw [1]
If you go into word and click the insert table you will see a section that says header, footer and page number. That is where you add a head and page number. 
4 0
4 years ago
Define application software​
sp2606 [1]

Answer: An application software is a type of software that the user interacts with, while a system software is a type of software that the system interacts with.

Hope this helped you :)

7 0
3 years ago
Do the pros of interpersonal communication via social media outweigh the cons? Explain.
JulijaS [17]
Well in my opinion is that yes they do. The ability to be able to communicate with others so far way really helps society advance towards the future. And i cant stress of how the benefits of being able to share ideas with well anyone is so wonderful.

I hope this helps.
6 0
3 years ago
Read 2 more answers
Critical thinking questions Giving 30 points if you answer correctly!!!!
krek1111 [17]

Answer:

1. The reason hunting seasons are displayed all over the world in cave paintings is because of the necessity to hunt. Ancient people everywhere were nomads that relied on wild animals for the majority of their calories. The paintings likely served as an expression of the importance of hunting to their culture. It could have also been used as educational material for very young children to learn about hunting as well as its importance to their community.

Explanation:

I can't do 2nd because the image was cut off, sorry.

8 0
3 years ago
Other questions:
  • A ________ is when teachers develop a professional based network of people selected by him/her to pursue learning needs and shar
    12·1 answer
  • Write a character literal representing the (upper case) letter<br> a.
    13·1 answer
  • For C programming language, what does it mean when you have an exclamation mark after an equal sign? ie:
    5·1 answer
  • What term is used to describe an individual's money and personal property? budget income assets finances
    12·2 answers
  • Based on your understanding of Moore’s Law, what do you predict will be the next trend in the evolution of computers?
    10·1 answer
  • What does "scanf(\"%d\" mean?
    13·2 answers
  • The older computer had a CPU that ran at 266MHz compared to a current CPU that runs 3.7GHz. How many times faster is the new CPU
    7·1 answer
  • How do you think the blitz might have affected civilian morale in london
    15·1 answer
  • Did you know you can buy a Passport Online?
    12·2 answers
  • Which UPPER function is written so that all text in cell B4 will be capitalized? O=UPPER(B4) O=UPPER[B4] O UPPER B4 O=UPPER
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!