Random-num-operator
import random
number=[1,2,3,4,5,6,7,8,9,10]
operator=['+','-','*','/']
num1=random.sample(number,1)
num2=random.sample(number,1)
op=random.sample(operator,1)
print(num1[0])
print(num2[0])
print(op[0])
q1=num1[0]
q2=num2[0]
if(op[0]=='+'):
A=q1+q2
elif(op[0]=='-'):
A=q1-q2
elif(op[0]=='*'):
A=q1*q2
elif(op[0]=='/'):
A=q1/q2
else:
print('ERROR')
print(num1,op[0],num2,'=',A)
Random
import random
a=random.randint(1,20)
guess=input('Please enter the number from 1-20: ')
guess=int(guess)
if guess ==a:
print('The number is' ,a, 'You win')
else:
print('The number is' ,a, 'You lose')
Randint
from random import randint
numbers=[ ]
print('random numbers: ')
for i in range(10):
n= randint(1, 100)
print(n, end=' ')
numbers.append(n)
s=sum(numbers)
a=s/len(numbers)
print('\nsum= %d ' %s)
print('Average= %f' %a)
quiz-game
print('Welcome to quiz')
answer=input('are you ready to play the quiz? (yes/no): ')
score=0
total_questions=3
if answer.lower()=='yes':
answer=input('Question 1: What is your school: ')
if answer.lower()=='saengthong':
score +=1
print('correct')
else:
print('wrong answer: (')
answer=input('Question 2: Are you boy?: ')
if answer.lower()=='yes':
score +=1
print('correct')
else:
print('Wrong answer:( ')
answer=input('''Question 3: What is your teacher name?: ''')
if answer.lower()=='ake':
score +=1
print('correct')
else:
print('Wrong answer')
print('Thank for playing')
mark=(score/total_questions)*100
print('Mark obtain: ',mark)
print('BYE')
Hilo
import random
num1=random.randint(0,100)
x=-1
while(x!=num1):
x=int(input('Please enter the first number: '))
if(x==num1):
print('You are correct')
elif(x>num1):
print('The number you have guessed is too high')
elif(x<num1):
print('The number you have guessed is too low')
Guessing number
target=65
print('*** Guess the number ***')
while(True):
num=int(input('Input your number that you guessed: '))
if(num==target):
break
else:
print('The number you guessed is incorrect, try again')
print('The number you guessed is correct, congrat')
calculate
def calculate():
operation = input('''
Please type in the math operation you would like to complete:
+for assition
-for substraction
*for multiplication
/for division
''')
number_1=int(input('Please enter the first number: '))
number_2=int(input('Please enter the seond number: '))
if operation=='+':
print(number_1,'+',number_2,'=',number_1+number_2)
elif operation=='-':
print(number_1,'-',number_2,'=',number_1-number_2)
elif operation=='*':
print(number_1,'*',number_2,'=',number_1*number_2)
elif operation=='/':
print(number_1,'/',number_2,'=',number_1/number_2)
else:
print('You have not type a valid operator, Please run the program again')
again()
def again():
calc_again=input('''
Do you want to calculate again?
Please type Y for YES and N for NO.
''')
if calc_again.upper()=='Y':
calculate()
elif calc_again.upper() =='N':
print('See you later')
else:
calc_again()
calculate()
For-positive
n=int(input('Input an interger: '))
if(n>0):
print('x is positive number')
print('Show number from 0 to %d' % (n-1))
else:
print('x is negative number')
for i in range(n):
print(i)
datetime
from datetime import datetime
time=datetime.now().time()
print('current Time=',time)
import datetime
date_object=datetime.date.today()
print(date_object)
from datetime import date
today=date.today()
d1=today.strftime('%d/%m/%y')
print('d1=',d1)
d2=today.strftime('%B/%d/%y')
print('d2=',d2)
d3=today.strftime('%m/%d/%y')
print('d3=',d3)
d4=today.strftime('%b-%d%y')
print('d4=',d4)