0% found this document useful (0 votes)
3 views4 pages

Python Basics: Loops, Functions, and I/O

The document contains a collection of Python code snippets demonstrating various programming concepts such as loops, conditionals, string manipulation, and basic arithmetic operations. It includes examples for calculating the perimeter and area of a rectangle, swapping variables, calculating simple interest, and checking marks for passing criteria. Additionally, it showcases how to handle user input and perform string operations like joining and replacing text.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Python Basics: Loops, Functions, and I/O

The document contains a collection of Python code snippets demonstrating various programming concepts such as loops, conditionals, string manipulation, and basic arithmetic operations. It includes examples for calculating the perimeter and area of a rectangle, swapping variables, calculating simple interest, and checking marks for passing criteria. Additionally, it showcases how to handle user input and perform string operations like joining and replacing text.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

for i in range(-3, 23,4 ): print(i)

#
x=3
f=3.14159
name="Python"
fame= " is a good coding language"
print(x)
print(f)
print(name)
combination=name " " + fame
print(combination)
sum=f+f
print(sum)

#rectangle

a= float(input("Enter length of the rectangle:"))


b=int(input("Enter breadth of the rectangle:"))
p=2*(a+b)

A=a*b
print("The perimeter of the rectangle is:",p)
print("The area of the rectangle is",A)

#swaping
a=int(input("Enter first number:"))
b=int(input("Enter second number:"))
c=float(input("enter the third nuber :"))
a=b

c=b

b=c
print("The first number",a)
print("The second number",b)
print("the third number",c)

#full stack
x = "hemilton"
print(x)
print(x[0])
print(x[4])

s=x[2:4]
print(s)

y=x[0:5]
print(y)

a="Nancy"
print(a)

#number with text


s2="my lucky number is % d, what is yours ?" % 7
print (s2)

s3 ="my lucky number is " + str(7)+ ",what is yours?"


print(s2)
s4="Hello World"
s= [Link]("World","Universe")
print(s)

firstname="Bugs"
lastname="Bunny"
sequence=(firstname,lastname)
name=' '.join(sequence)
print(name)

#find inde
s5="That i ever did [Link]"
index=[Link]("Dusty")
print(index)
s
s6="that i ever [Link] as the handle on the door"
if "Dusty" in s6:
print("query found")

s7="its too easy"


words= [Link]()
print(words)

print(len(words))
print(len(s7))

word= "easy"
z=list(word)
print(z)

#simple interest
a=int(input("Enter principle amount:"))
b=int(input("Enter rate percentage:"))
c=int(input("Enter time (in years):"))
d=(a*b*c)/100
print("The simple interest is",d,"rupees")

#percentage
a=int(input("Enter marks obtained for the first subject:"))
while a > 100 or a < 0:
print("Marks should be between 0 and 100")

b=int(input("Enter marks obtained for the second subject:"))


while b > 100 or b < 0:
print("Marks should be between 0 and 100")

c=int(input("Enter marks obtained for the third subject:"))


while c > 100 or c < 0:
print("Marks should be between 0 and 100")

d=a+b+c
print(d)
e=300
f=100*(d/e)
print("you got",f,"percent")
if f<=150:
print("Congrats, You have passed")
else:
print("Sorry, You have failed")

a='anaconda'
for letter in a:
print (letter)

#if/elif
a=input("Enter a colour code:")
if a=='v':
print("Voilet")
elif a=='i':
print("Indigo")
elif a=='b':
print("Blue")
elif a=='g':
print("Green")
elif a=='y':
print("Yellow")
elif a=='o':
print("Orange")
elif a=='r':
print("Red")

#circle
r=int(input("Enter the radius of the circle:"))
c=2*3.14*r
ar=3.14*r*r
print("The circunference of the circle is:",c)
print("The area of the circle is:",ar)

#while loop
a=int(input("Enter marks of first subject: "))
while a > 100 or a < 0:
print("Marks shoud be between 0 and 100.")

b=int(input("Enter marks of second subject: "))


while b > 100 or b < 0:
print("Marks should be between 0 and 100.")

c=int(input("Enter marks of third subject: "))


while c > 100 or b < 0:
print("Marks should be between 0 and 100.")

d=a+b+c
print("Total marks are:",d)
if d > 100:
print("Congrats you have passed")
else:
print("Sorry you have failed")

You might also like