|
Modulo(%)
|
Finding the remainder
|
|
Syntax
|
Grammar/ Structure of language
|
|
/
|
divide(float)
|
|
//
|
divide(integer)
|
|
True or anything
|
True
|
|
False and anything
|
False
|
|
string* string
|
Fail!!
|
|
string ** string
|
Fail!!
|
|
string ** number
|
Fail!!
|
user_input = input("write down string")
print(input)
letter_num = 0
reverse = ""
while letter_num < len(user_input):
reverse = user_input[letter_num] + reverse
letter_num = letter_num + 1
print ("Reverse: ",reverse)
if reverse == user_input:
print("This is palindrome")
else:
print("This is not a palindrome")
import random
mylist = ['lion', 'cheetah', 'panther', 'cougar', 'leopard']
random_item = random.choice(mylist)
Chances = 5
Score = 0
while Chances > 0:
print("Words:['lion', 'cheetah', 'panther', 'cougar', 'leopard']")
user_guess = input("Guess a word: ")
if user_guess == random_item:
print("That's correct!")
Score = Score+100
print("Chances remaining",'',Chances)
random_item = random.choice(mylist)
print("Score is",'',Score)
else:
if user_guess in mylist:
print("Sorry, wrong choice!")
Chances = Chances - 1
print("Chances remaining",'',Chances)
print("Score is",'',Score)
else:
print("Sorry, that is not even in the list!")
Chances = Chances - 1
print("Chances remaining",'',Chances)
print("Score is",'', Score)
if Chances == 0:
print("Gameover",'',"The word is",'',random_item)
print("Final score is",'',Score)
for num in range(100):
print (num) # prints all numbers from 0 – 99
for num in range(5, 50):
print(num) #prints all numbers from 5 - 49
if user_guess in mylist:
print("Sorry, tht's wrong")
else:
print("Sorry It is not in choice")
def volumeofprism(b,h,l):
volume = areaofTriangle(b,h) * l
return volume
user_length = float(input('Enter the length of the prism: '))
print ("The volume of the prism is", volumeofprism(user_base,user_height,user_length))
num = 2
while 1 < num and num <101 :
print(num)
num = num + 2
def max3 (num1,num2,num3):
if num1>num2 and num1>num3:
largestvalue = num1
elif num2>num3 and num2>num1:
largestvalue = num2
else:
largestvalue = num3
return largestvalue
print (max3(9,100,25))
print (max3(69,85,1))
print (max3(75,9,33))
def maxlist (list):
largestvalue = list [0]
for item in list:
if item > largestvalue:
largestvalue = item
return largestvalue
mylist = [1,2,3,4,103,100,89,57]
print (maxlist(mylist))
def isPalindrome(word):
letter_num = 0
reverse = ""
while letter_num < len(user_word):
reverse = user_word[letter_num] + reverse
letter_num = letter_num + 1
if word == reverse:
return True
else:
return False
while True:
user_word = input("Enter the word")
word = len(user_word)
print(word)
if user_word == "quit":
break
if isPalindrome(user_word):
print(user_word, "is a palindrome")
else:
print(user_word, "is not a palindrome")
user_number = input("Please enter the number")
number = int(user_number)
countdown_string = ""
while number>0:
countdown_string = countdown_string + str(number)
number = number - 1
print (countdown_string)
word = input("enter the word")
letter_num = 0
reverse = ""
while letter_num < len(word):
reverse = word[letter_num] + reverse
letter_num = letter_num + 1
print ("Reverse: ",reverse)
user_number = input ("Please enter the number")
number = int(user_number)
binary_string = ""
while (number>0):
remainder = number%2
binary_string = str(remainder) + (binary_string)
number = number//2
print ("Binary string is", binary_string)
mystr = "Hello"
letter_num = 0
while letter_num < len(mystr):
print (mystr[letter_num])
letter_num = letter_num + 1
H
e
l
l
o
def areaofcircle (r):
if r <= 0:
return "Error: Invalid radius"
pi = 3.1415
area = pi\*r\*\*2
return area
user_radius = input ('Enter the radius')
r = float(user_radius)
print("The area of circle is",areaofcircle(r))
def printdefinitions(word):
if word == "Variable":
print ('lo')
elif word == "Function":
print ('fun')
elif word == "Parameter" or word == "Argument":
print ('para')
elif word == "Function call":
print ('call')
elif word == "String":
print ("stri")
else:
print ("Unknown Word")
return
while True:
user_input = input ("Enter the word:")
printdefinitions(user_input)
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.