Python Programming

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

1.

#print(4 * (6 + 5))

#print(4 * 6 + 5)

#print(4 + 6 * 5)

#print(3 + 1.5 + 4)

3. x=int(input("Enter the value:"))

num_sqrt = x ** 0.5

print('The square root of %0.3f is %0.3f'%(x ,num_sqrt))

print("The Square value is:",x*x)

4. x="hello"

print(x[1])

5.x="helloo"

print(x[1:3])

6. x="hello"

print(x[-1])

7. string = input("Please enter your own String : ")


if(string == string[:: - 1]):
print("This is a Palindrome String")
else:
print("This is Not a Palindrome String")

8. c=input("Enter the string:")


f=len(c)
print(f)
if(f%2==0):
print("the word is even")
else:
print("The word is odd")
9.

10. import sys

user1 = input("What's your name?")


user2 = input("And your name?")
user1_answer = input("%s, do yo want to choose rock, paper or scissors?" % user1)
user2_answer = input("%s, do you want to choose rock, paper or scissors?" % user2)

def compare(u1, u2):


if u1 == u2:
return("It's a tie!")
elif u1 == 'rock':
if u2 == 'scissors':
return("Rock wins!")
else:
return("Paper wins!")
elif u1 == 'scissors':
if u2 == 'paper':
return("Scissors win!")
else:
return("Rock wins!")
elif u1 == 'paper':
if u2 == 'rock':
return("Paper wins!")
else:
return("Scissors win!")
else:
return("Invalid input! You have not entered rock, paper or scissors, try again.")
sys.exit()

print(compare(user1_answer, user2_answer))
11. from datetime import datetime
name=input("Enter you name:\t")
age=int(input("Enter age:\t"))
fyear=int((100-age) + datetime.now().year)
print(fyear)
print ('Hello %s. You are %s years old. You will turn 100 years old in %s.' %(name,age,fyear))

You might also like