0% found this document useful (0 votes)
80 views

Practicals PDV PRASAD

The document contains examples of Python print statements demonstrating basic string formatting and literals. It also includes examples of variables, lists, loops, conditional statements, functions, and global variables.

Uploaded by

Devi Vara Prasad
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)
80 views

Practicals PDV PRASAD

The document contains examples of Python print statements demonstrating basic string formatting and literals. It also includes examples of variables, lists, loops, conditional statements, functions, and global variables.

Uploaded by

Devi Vara Prasad
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/ 5

print("The itsy bitsy spider climbed up the waterspout.

")
print()
print("Down came the rain and washed the spider out.")
____________________________________________________________
print("The itsy bitsy spider\nclimbed up the waterspout.")
print()
print("Down came the rain\nand washed the spider out.")
____________________________________________________________
print("The itsy bitsy spider\nclimbed up the waterspout.")
print()
print("Down came the rain\nand washed the spider out.")
_____________________________________________________________
print("The itsy bitsy spider" , "climbed up" , "the waterspout.")
_____________________________________________________________
print("My name is", "Python.")
print("Monty Python.")
_____________________________________________________________
print("My name is", "Python.", end=" ")
print("Monty Python.")
____________________________________________________________
print("My name is ", end="")
print("Monty Python.")
_____________________________________________________________
print("My", "name", "is", "Monty", "Python.", sep="-")
____________________________________________________________
print("My", "name", "is", sep="_", end="*")
print("Monty", "Python.", sep="*", end="*\n")
_________________________________________________________________
print("Programming","Essentials","in")
print("Python")
_______________________________________________________________
LITERALS

print("2")
print(2)
print(0o123)
print(0x123)

print(2 * 3)
print(2 * 3.)
print(2. * 3)
print(2. * 3.)

print(6 / 3)
print(6 / 3.)
print(6. / 3)
print(6. / 3.)

print(6 // 3)
print(6 // 3.)
print(6. // 3)
print(6. // 3.)

print(6 // 4)
print(6. // 4)

print(-6 // 4)
print(6. // -4)

print(14 % 4)
print(12 % 4.5)

print(-4 + 4)
print(-4. + 8)

print(-4 - 4)
print(4. - 8)
print(-1.1)
print(+2)

print(9 % 6 % 2)

print(2 * 3 % 5)
print((5 * ((25 % 13) + 100) / (2 * 13)) // 2)

var = 1
print(var)

var = 1
account_balance = 1000.0
client_name = 'John Doe'
print(var, account_balance, client_name)
print(var)

var = 1
print(Var)
var = "3.7.1"
print("Python version: " + var)

var = 100
var = 200 + 300
print(var)

var = 1 print(var)
var = var + 1 print(var)
var = 100 var = 200 + 300
print(var)

a = 3.0
b = 4.0
c = (a ** 2 + b ** 2) ** 0.5
print("c =", c)

print("Tell me anything...")
anything = input()
print("Hmm...", anything, "... Really?")

leg_a = float(input("Input first leg length: "))


leg_b = float(input("Input second leg length: "))
hypo = (leg_a**2 + leg_b**2) ** .5
print("Hypotenuse length is", hypo)

fnam = input("May I have your first name, please? ")


lnam = input("May I have your last name, please? ")
print("Thank you.")
print("\nYour name is " + fnam + " " + lnam + ".")

print("+" + 10 * "-" + "+")


print(("|" + " " * 10 + "|\n") * 5, end="")
print("+" + 10 * "-" + "+")

# break - example

print("The break instruction:")


for i in range(1, 6):
if i == 3:
break
print("Inside the loop.", i)
print("Outside the loop.")

# continue - example

print("\nThe continue instruction:")


for i in range(1, 6):
if i == 3:
continue
print("Inside the loop.", i)
print("Outside the loop.")

var = 17
varRight = var >> 1
varLeft = var << 2
print(var, varLeft, varRight)

numbers = [10, 5, 7, 2, 1]
print("List content:", numbers) # printing original list content

numbers = [10, 5, 7, 2, 1]
print("Original list content:", numbers) # printing original list content

numbers[0] = 111
print("\nPrevious list content:", numbers) # printing previous list
content
numbers[1] = numbers[4] # copying value of the fifth element to the
second
print("Previous list content:", numbers) # printing previous list content

print("\nList length:", len(numbers)) # printing the list's length

numbers = [10, 5, 7, 2, 1]
print("Original list content:", numbers) # printing original list content

numbers[0] = 111
print("\nPrevious list content:", numbers) # printing previous list
content

numbers[1] = numbers[4] # copying value of the fifth element to the


second
print("Previous list content:", numbers) # printing previous list content

print("\nList's length:", len(numbers)) # printing previous list length

###

del numbers[1] # removing the second element from the list


print("New list's length:", len(numbers)) # printing new list length
print("\nNew list content:", numbers) # printing current list content

###

numbers = [111, 7, 2, 1]
print(numbers[-1])
print(numbers[-2])

myList = [10, 1, 8, 3, 5]
total = 0

for i in range(len(myList)):
total += myList[i]

print(total)

myList = [0, 3, 12, 8, 2]

print(5 in myList)
print(5 not in myList)
print(12 in myList)
def myFunction():
global var
var = 2
print("Do I know that variable?", var)

var = 1
myFunction()
print(var)

You might also like