[go: up one dir, main page]

0% found this document useful (0 votes)
14 views2 pages

Comp Programs

The document contains various Python code snippets demonstrating variable tracing, type conversion, string manipulation, and basic operations. It includes examples of loops, input handling, string slicing, concatenation, and the use of escape characters. Each code block is followed by a print statement to display the results of the operations performed.

Uploaded by

aatiefsharaf14
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)
14 views2 pages

Comp Programs

The document contains various Python code snippets demonstrating variable tracing, type conversion, string manipulation, and basic operations. It includes examples of loops, input handling, string slicing, concatenation, and the use of escape characters. Each code block is followed by a print statement to display the results of the operations performed.

Uploaded by

aatiefsharaf14
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/ 2

#Variable tracing

speed = 30
while speed < 65:
speed = speed + 10
print(speed)

#Integers
a=1.2
a=int(a)
print(a)

#convert miles to kilometres


miles = int(input("Please enter the distance in miles:"))
kilometre = miles * 1.61
print(kilometre)

#String
number = 2001.32
numberString = str(number)
print(numberString)

#Characters in a string
x = len("bananas")
print (x)

#convert to upper case


message = "important message!"
upperMessage = message.upper()
print(upperMessage)

#Count character
message = "mississippi"
letterS = message.count("s")
print(letterS)

#Escape characters
phrase = "\"l agree,\" she said, nodding her head."
print(phrase)

#Escape characters
block = "Product\tPrice\nRadio\t699"
print(block)
#String slicing 1
string = "computing"
print(string[0:3])

#String slicing
string = "computing"
print(string[6:])

#Simple concatenation
firstName = "Sandeep"
lastName = "Korren"
print(firstName + " " + lastName)

#concatenation
apartmentNumber = 161
streetName = "Emirates Road"
city = "Dubai"
address = (str(apartmentNumber) +" "+ streetName +" "+ city)
print(address)

You might also like