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

Python Programming

This document contains 11 code snippets demonstrating various Python programming concepts: 1) Arithmetic operations 2) Taking square root of a number 3) Slicing strings 4) Accessing last/first characters of a string 5) Checking for palindrome 6) Checking length of string 7) Rock paper scissors game 8) Calculating year when user turns 100

Uploaded by

Papitha
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)
60 views

Python Programming

This document contains 11 code snippets demonstrating various Python programming concepts: 1) Arithmetic operations 2) Taking square root of a number 3) Slicing strings 4) Accessing last/first characters of a string 5) Checking for palindrome 6) Checking length of string 7) Rock paper scissors game 8) Calculating year when user turns 100

Uploaded by

Papitha
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/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy