0% found this document useful (0 votes)
108 views5 pages

Console Input and Output: Exercise

The document discusses a lab exercise on console input and output in Python. It contains examples of taking user input, controlling output position, and summarizing errors in code snippets. The exercises include writing programs to: 1) print a student's biodata entered from the console, 2) ask the user what food they like and print it in uppercase, and 3) take marks for 5 courses as input and calculate average and percentage. The output for sample runs of the programs is also shown.

Uploaded by

John wick
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)
108 views5 pages

Console Input and Output: Exercise

The document discusses a lab exercise on console input and output in Python. It contains examples of taking user input, controlling output position, and summarizing errors in code snippets. The exercises include writing programs to: 1) print a student's biodata entered from the console, 2) ask the user what food they like and print it in uppercase, and 3) take marks for 5 courses as input and calculate average and percentage. The output for sample runs of the programs is also shown.

Uploaded by

John wick
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/ 5

Programming Fundamentals (SWE-102) SSUET/QR/114

LAB # 03

CONSOLE INPUT AND OUTPUT

OBJECTIVE
Taking input from user and controlling output position.

EXERCISE

A. Point out the errors or undefined/missing syntax, if any, in the following python
programs.

1. print("Hello \b World!")

There is no error.

2. first_number = str ( input ("Enter first number") ) second_number = str


( input ("Enter second number") )
sum = (first_number + second_number)
print("Addition of two number is: ", sum)

(Str) causing the error.If we use (int) instead of (str) the program will run.

3. age = 23
message = "Happy " + age + "rd Birthday!" print(message)

The sum(+) causing the error if we use comma(,) instead os sum(+) the program
will run.

B. What would be the output of the following programs:

Lab 03: Console Input and Output 1


Programming Fundamentals (SWE-102) SSUET/QR/114

1. a=5
print("a =", a, sep='0', end=',')

Output:
>> %Run 'lab 3 B1.py'
a =05,

2. name = input("Enter Employee Name") salary = input("Enter salary")


company = input ("Enter Company name") print("Printing Employee Details")
print ("Name", "Salary", "Company")
print (name, salary, company)
Code:
name = input("Enter Employee Name:")
salary = input("Enter salary:")
company = input ("Enter Company name:")
print("**Printing Employee Details**")
print ("Name", "Salary", "Company")
print (name, salary, company)

Output:
>> %Run 'lab 3 b2.py'
Enter Employee Name:Imran
Enter salary:100000
Enter Company name:Imran Shabeer Construction Company
**Printing Employee Details**
Name Salary Company
Imran 100000 Imran Shabeer Construction Company

3. n1=int(input('"enter n1 value'))
n2=int(input('enter n2 value'))

Lab 03: Console Input and Output 2


Programming Fundamentals (SWE-102) SSUET/QR/114

Output:
>>> %Run 'lab 3 b3.py'
"enter n1 value10
enter n2 value50

C. Write Python programs for the following:

1. Write a program to print a student’s bio data having his/her Date of birth, Roll no,
Section, Percentage and grade of matriculation and Intermediate. All the fields
should be entered from the console at run time.
Code:
print("\t\t\t\t**Bio Data**\n")
print("\t\t\t *Personal Profile*\n")
FullName=str(input("Enter Full Name\t\t:\t"))
FatherNam=str(input("Enter Father Name\t\t:\t"))
D_O_B=(input("Enter date of birth\t\t:\t"))
Roll_no=(input("Enter roll no \t\t\:\t"))
Sec=str(input("Enter Section\t\t:\t"))
Per_in_Matric=str(input("Enter Percentage in Matric\t:\t"))
Per_in_Inter=str(input("Enter Percentage in Inter\t:\t"))
print("\n")
print("Full Name =\t\t\t:\t",FullName)
print("Father Name =\t\t\t:\t",FatherNam)
print("Date Of Birth =\t\t\t:\t",D_O_B)
print("Section =\t\t\t\t:\t",Sec)
print("Matric Percentage =\t:\t",Per_in_Matric)
print("Inter Percentage =\t:\t",Per_in_Inter)

Lab 03: Console Input and Output 3


Programming Fundamentals (SWE-102) SSUET/QR/114

Output:
> %Run 'lab 3 biodata.py'
**Bio Data**

*Personal Profile*

Enter Full Name : Imran Baloch


Enter Father Name : Shabeer Ahmed
Enter date of birth : 15.01.2002
Enter roll no : 2021f-BSE-314
Enter Section : B
Enter Percentage in Matric : 87%
Enter Percentage in Inter : 70%

Full Name = Imran Baloch


Father Name = Shabeer Ahmed
Date Of Birth = 15.01.2002
Section = : B
Matric Percentage = 87%
Inter Percentage = 70%
>>>

2. Write a program that asks the user what kind of food they would like. Print a
message about that food, such as “Let me see if I can find you a Chowmein”. Food
name must be in uppercase. (hint: use upper( ) for food name)
Code:
Food_name=input("What kind of food do you like")
print("let me see if i can find you a",Food_name.upper())

Output:
>>> %Run 'lab 3 food web.py'
What kind of food do you likebiryani
let me see if i can find you a BIRYANI

Lab 03: Console Input and Output 4


Programming Fundamentals (SWE-102) SSUET/QR/114

3. Take the marks of 5 courses from the user and calculate the average and percentage,
display the result:
Eachcourse=50 marks
Total_marks=
course1+course2+course3+course4+course5
average=Total_marks/5 percentage=(Total_marks x
100)/250

Code:
print("\t\tProgram to display Exam results")
Pf=int(input("Enter your Pf Number:"))
Itc=int(input("Enter your itc Number:"))
English=int(input("Enter your English Number:"))
Islamiat=int(input("Enter your Islamiat Number:"))
Math=int(input("Enter your Math Number:"))
print("Each course has maximum 50 marks")
Totalmarks=Pf+Itc+English+Islamiat+Math
average=Totalmarks/5
print("average=",average)
percentage=(Totalmarks*100)/250
print("percentage=",percentage)

Output:

**Program to display Exam results**


Enter your Pf Number:45
Enter your itc Number:40
Enter your English Number:38
Enter your Islamiat Number:48
Enter your Math Number:30
Each course has maximum 50 marks
average= 40.2
percentage= 80.4
>>>

Lab 03: Console Input and Output 5

You might also like