0% found this document useful (0 votes)
4 views

4.Taking Input From the User in Python

This lesson covers the use of the input() function in Python for taking user input, including strings, integers, and float values. It also provides a simple program to add two numbers and outlines the rules for naming variables in Python. Key rules include starting with a letter or underscore, avoiding special characters, and case sensitivity.

Uploaded by

garv222008
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 views

4.Taking Input From the User in Python

This lesson covers the use of the input() function in Python for taking user input, including strings, integers, and float values. It also provides a simple program to add two numbers and outlines the rules for naming variables in Python. Key rules include starting with a letter or underscore, avoiding special characters, and case sensitivity.

Uploaded by

garv222008
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
You are on page 1/ 2

Mayuri’s Online Computer Classes

Taking Input in Python

In this lesson, we will see how to use input( ) function.

input( )
The input( ) function allows user input.

For example,

The code below takes String input from the user. String is a sequence of
characters.

print('Enter your name:')


x = input()
print('Hello, ' + x)

We can also write as,

x = input('Enter your name:')


print('Hello, ' + x)

As we have seen in the above example that when we receive the input using
input() function in the form of String. To convert the string input to integer we
use the int() function with the input( ) function.

num = int(input("Enter an Integer: "))


print(num)

In the similar way, we can also accept float values (decimal values) by using
float( ) function with the input( ) function.

num = float(input("Enter a float value: "))


print(num)

Mayuri’s Online Computer Classes 1


Program to add two numbers:

first_num = int (input(“Enter first number”))

second_num = int (input(“Enter second number”))

s = first_num + second_num

print(“Addition of two numbers is: ” , s)

As you know variables are like containers for storing values (data).

There are certain rules to be followed while naming them.

Rules for name variables:


1. A variable name must start with a letter or the underscore character.
2. A variable name cannot start with a number.
3. A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _). Cannot contain any other special character
like % & @ etc.
4. Variable names are case-sensitive (name, NAME and Name are
considered as three different variables).
5. Cannot give keywords as variable names.

****************************

Mayuri’s Online Computer Classes 2

You might also like