Ads

AI week 2 lab task

 program 1:

#string with single quotes

string1='welcome to the AI Class'

print("String with the use of single quotes")

print(string1)


#string with double quotes

string2="welcome to the AI Class"

print("String with the use of double quotes")

print(string2)


#string with triple quotes

string3='''"welcome to the AI Class"'''

print("String with the use of triple  quotes")

print(string3)


#string with triple quotes allows multiple lines

string3='''"welcome

to the AI 

Class"'''

print("String with the use of triple quotes allows multiple lines")

print(string3)


 program 2:

#Access characters of String

String1 = "ArtificialIntelligence"

print("Initial String: ")

print(String1)

# Printing First character

print("\nFirst character of String is: ")

print(String1[0])

# Printing Last character

print("\nLast character of String is: ")

print(String1[-1])


 program 3:

#String Slicing:

MyString='Learn Python'

print(MyString[0:5])

print(MyString[-12:-7],"\n")

print(MyString[6:])

print(MyString[:-7],"\n")

print(MyString[:])


 program 4:

#String Concatenation:
text_1='learn'
text_2='python'
MyString= text_1+text_2
print(MyString)

MyString= text_1+" "+text_2
print(MyString)

 program 5:
#print datatype complex
c=2+4j
print(type(c))

 program 6:
#print datatype integer
a=5
print(type(a))

 program 7:
#print datatype float
a=5.7
print(type(a))


 program 8:
#lab TASK 2

name = "Ayesha"  # String
roll_no = 215  # Integer
cgpa = 3.78  # Float

print("Name:", name)
print("Roll Number:", roll_no)
print("CGPA:", cgpa)


print("Type of name:", type(name))
print("Type of roll_no:", type(roll_no))
print("Type of cgpa:", type(cgpa))


 program 9:
#taking user input

name = input("Enter your name: ")  # String input
roll_no = int(input("Enter your roll number: "))  # Integer input
cgpa = float(input("Enter your CGPA: "))  # Float input


print("\nName:", name)
print("Roll Number:", roll_no)
print("CGPA:", cgpa)


print("\nType of name:", type(name))
print("Type of roll_no:", type(roll_no))
print("Type of cgpa:", type(cgpa))

Post a Comment

0 Comments