0% found this document useful (0 votes)
6 views6 pages

Python Intro

The document provides an overview of the print() and input() functions in Python, including various examples of their usage for outputting text, numbers, and user input. It also includes exercises for practicing these concepts, such as printing personal information, performing calculations, and creating simple programs that interact with the user. Additionally, it presents a challenge to create a basic login system.

Uploaded by

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

Python Intro

The document provides an overview of the print() and input() functions in Python, including various examples of their usage for outputting text, numbers, and user input. It also includes exercises for practicing these concepts, such as printing personal information, performing calculations, and creating simple programs that interact with the user. Additionally, it presents a challenge to create a basic login system.

Uploaded by

ndombi037
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

print() output function in Python with different examples.

🔹 Examples of Using Output Function (print())

1. Basic text output

print(" Welcome to ICT Club)

🖥 Output:

Welcome to ICT Club

2. Printing numbers

print(100)

print(3.14)

🖥 Output:

100

3.14

3. Printing multiple values

name = "Alice"

age = 18

print("My name is", name, "and I am", age, "years old.")

🖥 Output:

My name is Alice and I am 18 years old.


4. Using escape characters (\n,\t)

print("Line1\nLine2\nLine3") # new lines

print("Name\tAge\tClass") # tabs (like a table)

🖥 Output:

Line1

Line2

Line3

Name Age Class

7. Printing calculations

a=5

b=3

print("Sum:", a + b)

print("Product:", a * b)

🖥 Output:

Sum: 8

Product: 15

Exercise

1. Write a program that prints Hello, Python!


2. Print your name and age using the print() function.
3. Print the numbers 10, 20, and 30 each on a separate line.
4. Print the following output using \n:
Red
Green
Blue
5. Print this table using \t:
Name Age
John 15
Mary 16
6. Write a program that stores your favorite food in a variable and prints:

My favorite food is ___

7. Print the sum, difference, and product of 15 and 7 in one program.


8. Write a program that asks the user for two numbers and prints their average.

INPUT FUNCTION
The input() function allows the program to ask the user for data.

🔹 Examples of Using Input Function (input())

1. Basic input

name = input("Enter your name: ")

print("Hello,", name)

2. Getting numbers (with conversion)

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

print("Next year you will be", age + 1)

🖥 Example run:

Enter your age: 17

Next year you will be 18

3. Getting decimal numbers

height = float(input("Enter your height in meters: "))

print("Your height is", height, "meters")


🖥 Example run:

Enter your height in meters: 1.72

Your height is 1.72 meters

4. Multiple inputs

first = input("Enter first name: ")

last = input("Enter last name: ")

print("Your full name is", first, last)

5. Simple calculator (with input)

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

print("The sum is", a + b)

7. Decision-making with input

password = input("Enter password: ")

if password == "python123":

print("Access granted ✅")

else:

print("Access denied ❌")


EXERCISE

🔹 Part A: Basic Input

1. Write a program that asks the user for their name and prints a greeting.
Example:

Enter your name: Alice

Hello, Alice

2. Ask the user to enter their school name and print:

You study at ___

🔹 Part B: Numbers with Input

3. Write a program that asks for the user’s age (as an integer) and prints how old they will
be in 5 years.

4. Ask the user to enter two numbers and print their sum.

5. Modify the program above to print their difference and product

🔹 Part C: Multiple Inputs

6. Write a program that asks for the user’s first name and last name separately, then prints
their full name.

7. Ask the user for their favorite subject and favorite color, then print a sentence that
combines them.
Example:

8. My favorite subject is Math and my favorite color is Blue.

🔹 Part D: Real-World Mini Programs

8. Ask the user for the length and width of a rectangle and calculate the area.

9. Ask the user for the current year and their birth year, then calculate their age.

🔹 Part E: Challenge ⭐
11. Create a program that works like a simple login system:

 Ask the user to enter a username and password.

 If they match "admin" and "1234", print "Login successful".

 Otherwise, print "Invalid login".

You might also like