Search Header Logo
input & output function

input & output function

Assessment

Presentation

Instructional Technology

10th Grade

Practice Problem

Medium

Created by

s tobgyal

Used 23+ times

FREE Resource

20 Slides • 6 Questions

1

input function, output function & Comments

By s tobgyal

2

​"Every leaf fall is not the end, but it is the beginning"

media

3

input() function:

is used to take input from the user during program execution.

Whatever the user types using input() is always stored as a string (text), even if it looks like a number or other data type.

variable = input("Message for the user")

media

4

1.       User Interaction
It lets users enter data while the program is running.

2.       Dynamic Programs
Makes programs flexible and responsive to user input.

3.       Real-World Use
Useful in applications like forms, games, quizzes, and data entry.

4.       Takes Custom Input
Allows users to provide their own values instead of hardcoded ones.

5.       Improves Usability
Makes programs more engaging and user-friendly.

​​Importance of input() Function in Python

5

media

​Demonstration.....

6

Write a Python program that asks the user to enter the following information:

  • Full name

  • Age

  • Grade

  • Favourite subject

Then, display the information in a clean format.

7

  1. Write a python program asks the users to enter their name and then displays the name on the screen.

  2. Write a Python program to ask the user to enter the marks of following subjects and display it accordingly:

    English

    Dzongkha

    Maths

    Science

    HCG

    ICT

    Economics

​​Activities:

8

media

9

Multiple Choice

What does the input() function do in Python?

1

A) It displays a message on the screen

2

B) It reads a line from standard input as a string

3

C) It executes a Python script

4

D) It pauses the program for a given time

10

Multiple Choice

How can you convert input from the user into an integer?

1

A) int(input("Enter number: "))

2

B) input(int("Enter number: "))

3

C) str(input("Enter number: "))

4

D) input("Enter number: int")

11

Multiple Choice

Which of the following statements is true about the input() function?

1

A) It can directly accept numeric input

2

B) It returns data in boolean format

3

C) It always returns data as a string

4

D) It reads multiple lines of input by default

12

​OUTPUT:
Output refers to the information or result produced by a computer after:

  1. Taking input

  2. Processing the input

  3. (Optionally) Storing the data

  4. Displaying or presenting the result

media

13

print() Function in Python

is used to display messages, variables, or results on the screen.

Syntax:

print(object(s), sep=' ', end='\n')

 

object(s): Text, numbers, variables, etc.

sep: Separator (default is space)

end: What to print at the end (default is newline \n)

 

14

print string:
print("Welcome to python programming")

#output: Welcome to Python! programming

using variable(s):
greet="Welcome to python programming"
print(greet)


#output: Welcome to python programming

15

Output Formatting in Python
means making your printed output look clean, aligned, or styled in a specific way.


Common Methods of Output Formatting:

1. Using commas in print(,)

2. String Concatenation (+)

3. Using f-strings

4. Using .format()

16

​1. Using commas in print()

print multiple objects on the same line using the print() function by separating the objects with commas. Automatically adds spaces between items.

 

Example:

print("I","Love","Bhutan")

#output: I Love Bhutan

17

2. String Concatenation (+)

joining two or more strings together into one string.  Joins strings together (only works with strings).

Example:

print("Hello"+"Karma")

#output: HelloKarma

name="Wangpo"
age=15
print(name+age)# cannot add because of different types
# instead use comma to join

18

3​. Using f-strings:

Just add an f before the string, and put variables or expressions inside {}. Easiest and most modern way (Python 3.6+).

Example:
name="Wangpo"

age=15

print(f'My name is {name} and i am {age} years old')


19

​4. Using .format()

an older but still useful way to insert values into strings before f-strings were introduced. The {} are placeholders, and .format() fills them in order.

Example:
name="Wangpo"

age=15

print('My name is {} and i am {} years old'.format(name,age))

20

Python comment(s):
Are used to
explain what the code does or leave notes for yourself or others. Used to make code easier to understand

Two types of comments:
1. Single line comments
#Comments here...bla bla
2. Multiline comments
'''this is more
than one line
comment
'''

21

Benefits of Using Comments in Code

1.       Improves Readability
Comments help explain what the code does, making it easier to understand.

2.       Eases Code Maintenance
Makes it easier to update or modify code later.

3.       Helps Debugging
Helps identify what each part of the code is supposed to do.

4.       Supports Teamwork
Other programmers can quickly understand your logic.

5.       Saves Time
Saves time for you and others when revisiting the code after a while.

22

media

23

Multiple Choice

What is the purpose of comments in Python code?

1

A) To make the program run faster

2

B) To describe code and make it easier to understand

3

C) To execute hidden instructions

4

D) To store data

24

Multiple Choice

What happens to the comment when the Python program runs?

1

A) It gets stored in memory

2

B) It is ignored by the interpreter

3

C) It produces an output

4

D) It causes a syntax error

25

Multiple Choice

Which of the following is used to display output in Python?

1

A) output()

2

B) echo()

3

C) print()

4

D) display()

26

media

input function, output function & Comments

By s tobgyal

Show answer

Auto Play

Slide 1 / 26

SLIDE