Professional Documents
Culture Documents
Python Functions
Python Functions
print("hello world")
"" => treated as word
print(10*"hello\n") => used for number of times to be written(10) and new lines(n)
print("hello\t") => used for tap (more space)
a=int(input("enter a num:")) => used to take input from the user, int = integer
print(a)
b=int(input("enter a num:"))
print(b)
if a>b:
print("a is max")
else:
print("b is max")
The code above is used for if and else statements
if a>18:
print("You are eligible to vote")
else:
print("No")
if a%5==0:
print("Yes")
else:
print("No")
Q- Check whether a question is positive, zero or negative.
if a>0:
print("Positive")
elif a==0:
print("Zero")
else:
print("Negative")
elif => else if ( used with if and else if there are more than two conditions)
Q- Take length and breadth measurements from the user to check whether it is a
rectangle or a square.
a=int(input("Enter the length"))
b=int(input("Enter the breadth"))
if a>b:
print("Rectangle")
elif b>a:
print("Rectangle")
else
print("Square")
if a==0:
print("Zero")
elif a%2==0:
print("Even")
else:
print("Odd")
if (a>b and b>c) or (a<b and b<c) or (b>a and a>c) or (a>b and c>b):
print("Scalene")
To avoid writing such a long code, we can use '!=' for not equals to.
Data types:
Dictionary
thisCar={"name":"sajdasjdh",
"age":545}
print(thisCar)
print(type(thisCar))
Dictionary length=> This function prints the name and age along with the type of
data.
print(len(thisdict))
for i in "python":
print(i)