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

Lab 01 Introduction To Python, Operator & String

This document contains the code and output for 4 tasks in a Python lab assignment on operators and strings. Task 1 demonstrates string methods like title(), concatenation, repetition and input/output. Task 2 works with string slicing. Task 3 defines and calls a function. The Exercise section contains 4 additional tasks - one calculates expressions with variables, one uses a formula, one manipulates string input/output, and the last demonstrates string stripping methods.

Uploaded by

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

Lab 01 Introduction To Python, Operator & String

This document contains the code and output for 4 tasks in a Python lab assignment on operators and strings. Task 1 demonstrates string methods like title(), concatenation, repetition and input/output. Task 2 works with string slicing. Task 3 defines and calls a function. The Exercise section contains 4 additional tasks - one calculates expressions with variables, one uses a formula, one manipulates string input/output, and the last demonstrates string stripping methods.

Uploaded by

Anum Khursheed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

Artificial Intelligence SSUET/QR/114

Lab 01
Introduction to Python, Operator & String
Lab Tasks
Task 01

Code:
message = "Sir Syed"
print (message)

message = input ("Enter No.")


print(message)

message = input ("Enter No.")


print(message)

a="university"
print(a.title())
print("Hello"+"Hello")
print(message + message)
print(a*4)

a= int (input("Enter No:"))


print (a)

Output:

Sir Syed
Enter No.5
5
Enter No.6
6
University
HelloHello
66
universityuniversityuniversityuniversity
Lab 01 Page 01 Anum Khursheed

2017-SE-014
Artificial Intelligence SSUET/QR/114

Enter No:7
7

Task 02

Code:
a="Sir Syed University"
print(a[2])
print (a[5:11])
print(a[:5])
print(a[5:])
print(a[0:5:2])
print(a[-2])

Output:

r
yed Un
Sir S
yed University
SrS
T

Task 03

Code:
def greet_user(username):
print("Hello,"+username.title()+"!")
greet_user('anum')

Output:
Lab 01 Page 01 Anum Khursheed

2017-SE-014
Artificial Intelligence SSUET/QR/114

Hello,Anum!

Exercise
Task 01

Code:
a= int (input("Enter No:"))
print (a)
mul=a+3
sub=mul*2
b=sub-4
result=b+3
print(result)

Output:

Enter No:90
90
185

Task 02

Code:
r= int (input("Enter No:"))
print (r)
formula= 3.17*r*r
print(formula)

Lab 01 Page 01 Anum Khursheed

2017-SE-014
Artificial Intelligence SSUET/QR/114

Output:

Enter No:7
7
155.32999999999998

Task 03

Code:
a=input("Enter your favourite color: ")

b=" "

print(a*10)
print(a,b*30,a)
print(a*10)

Output:

Enter your favourite color: Blue


BlueBlueBlueBlueBlueBlueBlueBlueBlueBlue
Blue Blue
BlueBlueBlueBlueBlueBlueBlueBlueBlueBlue

Task 04

Code:
a=input("Enter Name: \t ")

print("\t"+a)
print (a.strip())

Lab 01 Page 01 Anum Khursheed

2017-SE-014
Artificial Intelligence SSUET/QR/114

print (a.lstrip())
print (a.rstrip())

Output:

Enter Name: Intelligence


Intelligence
Intelligence
Intelligence
Intelligence

Lab 01 Page 01 Anum Khursheed

2017-SE-014

You might also like