###################################################
import random
#INSTRUCTIONS
# 1) COMPLETE QUESTIONS THAT ARE IN A RED BOX
# 2) DO NOT CHANGE THE MAIN METHOD NAMES!!!!!
# 3) READ COMMENTS FOR HELP
# 4) DELETE THE "RETURN" KEYWORD IN SOME PLACES
# 5) MAKE SURE THERE ARE NO SYNTAX ERRORS WHEN YOU UPLOAD!!!!
##################################################
#Question 1: The function roll(n) simulates the outcome of one random roll of an n-sided
dice. E.g. roll(6) will randomly return either 1,2,3,4,5 or 6. Write a sub-program that takes the
number of sides of the dice as a parameter and returns a player's score.
###################################################
def roll(n):
number = random.randint(1,n)
return number
#GET A RANDOM NUMBER USING THE RANDOM MODULE FROM 1 TO THE NUMBER
OF SIDES
#RETURN THIS VALUE TO MAIN FUNCTION
def numberOfSides():
sides= int(input("How many sides does your dice have? "))
#GET USER INPUT FOR THE NUMBER OF SIDES
return sides
def mainRoll():
n = numberOfSides()
print ("Your outcome is : " + str(roll(n)))
#PRINT THE NUMBER
mainRoll()
#############################################
# Question 2: Write a Python function to create and print a list where the values are square
of numbers between 1 and 30 (both included)
#############################################
def printListSquared(A):
, B = []
for num in A:
B.append(num*num)
#FILL IN THE ARRAY B WITH THE VALUES IN A SQUARED
return B
#RETURN THIS ARRAY TO THE MAIN METHOD
def mainPrintListSquared():
A=[
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30
]
listSquared = printListSquared(A)
print(listSquared)
#mainPrintListSquared()
################################################
# Question 3: Write a Python program to print the even numbers from a given list.
################################################
def evenNumbers(A):
B = []
for num in A :
if (num % 2) == 0 :
B.append(num)
return B
def mainEvenNumbers():
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
evenNumberArray = evenNumbers(A)
print(evenNumberArray)
#mainEvenNumbers()
####################################################
#Question 4: Write a Python function that takes a number as a parameter and check the
number is prime or not
###################################################