0% found this document useful (0 votes)
4 views12 pages

User Input and Type Conversion Guide

Uploaded by

eqaniqbal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

User Input and Type Conversion Guide

Uploaded by

eqaniqbal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is

User Input &


Type Conversion ?
User Input
User input is information we ask
the user to type while the
program is running.

It allows the program to


interact with the user and make
the program dynamic.
User Input
Example in real life:
Asking someone their name
Asking their age
Asking their favorite game
Syntax for
User Input

variable_name → the name


where the input will be stored
input()→ function that waits for
the user to type something
"Your question here: " →
message shown to the user
Example

Step-by-step:
Program shows: What is your name?
User types: Ali
Program prints: Hello Ali
The computer stores what the user
typed and we can use it later.
What is Type
Conversion?
Type conversion is changing the
type of a value from one type to
another.
Why we use it:
input() always gives text (string)
If we want to do math, we must
convert it to number
Syntax of Type
Conversion
Example
Practice
Questions
Ask the user for their name and age, then
print:
"Hello , you are years old!"
Ask the user for two numbers, then print
their sum and their difference.
Ask the user for length and width of a
rectangle, then print the area only.
Ask the user how many apples and
oranges they have, then print the total
fruits.
Practice
Questions
Ask the user if they have a pet (yes or no)
and print:
"You have a pet" if yes
"You don’t have a pet" if no
Ask the user for their favorite game and
print:
"Wow! I like too!"
Ask the user for a number, then print that
number multiplied by 2.
Any
or
Question
Any
Suggestion
?
Thanks for

listening !

You might also like