0% found this document useful (0 votes)
5 views3 pages

Python Input, Composition & Modulus Explained

The document explains the input() function in Python for taking user input, highlighting that input is read as a string by default. It also covers composition, where the result of one function can be used as input for another, and provides examples. Additionally, it describes the modulus operator (%) for finding remainders and its common uses, such as checking if a number is even or odd.

Uploaded by

rn646059
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)
5 views3 pages

Python Input, Composition & Modulus Explained

The document explains the input() function in Python for taking user input, highlighting that input is read as a string by default. It also covers composition, where the result of one function can be used as input for another, and provides examples. Additionally, it describes the modulus operator (%) for finding remainders and its common uses, such as checking if a number is even or odd.

Uploaded by

rn646059
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

Input, Composition and Modulus Operator

Created by: Prof. Pratiksha Rajnoor

1. Input

Definition:

In Python, the input() function is used to take data (information) from the user.

Syntax:

variable_name = input("Enter something: ")

Explanation:

The text inside quotes is shown on the screen (a prompt).

The user types something and presses Enter.

The input is always read as a string (text) by default.

Example:

name = input("Enter your name: ")

print("Hello,", name)

If you need a number as input:

age = int(input("Enter your age: "))

print("You will be", age + 1, "next year.")

---

2. Composition

Definition:

Composition means combining multiple operations or functions together to perform a task


in a single expression.

In simple terms: You can use the result of one function or operation as the input to another.
Example:

name = input("Enter your name: ")

print("Your name in uppercase is:", [Link]())

Here, the input() function’s result is used directly inside print(). That’s composition —
combining input() and print() in one statement.

Another example:

print(int(input("Enter a number: ")) + 5)

Explanation:

1. input() takes user input.

2. int() converts it to a number.

3. print() displays the final result — all in one line.

---

3. The Modulus Operator (%)

Definition:

The modulus operator % gives the remainder after dividing one number by another.

Syntax:

result = a % b

Example:

print(10 % 3) # Output: 1

print(8 % 2) # Output: 0
Common Uses:

To check if a number is even or odd:

num = int(input("Enter a number: "))

if num % 2 == 0:

print("Even number")

else:

print("Odd number")

To find cycles or repeat patterns (like every 7th day, every 3rd element, etc.)

You might also like