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

63e5e070392faQCR Lab 2pdf

This document outlines a lab session on Python basics, covering topics such as user input, type conversion, string manipulation, arithmetic, comparison, logical operators, and conditional statements. It includes examples of code snippets demonstrating each concept. The lab is conducted by Tooba Tehreem at Namal University on February 7, 2023.
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)
8 views3 pages

63e5e070392faQCR Lab 2pdf

This document outlines a lab session on Python basics, covering topics such as user input, type conversion, string manipulation, arithmetic, comparison, logical operators, and conditional statements. It includes examples of code snippets demonstrating each concept. The lab is conducted by Tooba Tehreem at Namal University on February 7, 2023.
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/ 3

QCR Lab 02

Namal University
07 February 2023

Lab Instructor: Tooba Tehreem


Course Instructor: Shahzad Arif

Outline
• Python Basics
• Input from User
• Type Conversion

• String Value
• Arithmetic Operator
• Comparison Operator

• Logical Operator
• Conditional Statement

Python Basics
Python is a popula language and it compile code line by line. To print any value
we use:
print(”hello world”)
we can print value by assigning it to any variable.
x = 48
print(x)

Input from User


To get value from user at run time, we can use:
name = input(”What is your name? ”)
print(”Hello ” + name)

1
Type Conversion
If we get value from user f = input(”first ”)
s = input(”second ”)
total= f+s
print(total)
In such situation, compiler print just input. It doesn’t add both values, just
print it. Compiler consider these values as strings.
v1 = input(”first ”)
v2 = input(”second ”)
total value= int(v1)+int(v2)
print(total value)
Another way is:
c1 = float(input(”first floating value”))
c2 = float(input(”second floating value”))
c total=c1+c2
print(c total)

String value
course = ”First year CS”
print(course.upper())
print(course.lower())
print((course.find(’y’)))
print((course.find(’E’)))
print(course.replace(’F’,’S’))
print(course.find(’year’))
print(”First” in course)
print(course)

Arithmetic Operator
print(10+5)
print(10*5)
print(10/4)
print(10//4)
print(10 % 7)
print(10 ** 2)
x = 10
x=x+6
print(x)

2
Comparison Operator
x = 5 == 8
print(x)

Logical Operator
x = 10
print((x > 10 and x < 17))
print((x > 16 or x < 19))
print(not x < 10)

Conditional Statement
if
x = 10
if x > 18:
print(”QCR lab”)
print(”first year”)
print(”Done”)
if-elif
a=5
b = 10
if b > a:
print(”b is greater than a”)
elif a == b:
print(”a and b are equal”)
if-else
a=5
b = 10
if b > a:
print(”b is greater than a”)
elif a == b:
print(”a and b are equal”)
else:
print(”a is greater than b”)

“Your time is limited, so don’t waste it living someone else’s life!”

You might also like