This not includes revision notes from some topics. It has programming and theory both combined. Some files with questions and answers. Some files with project examples of programming. And some files with deep knowledge of the theory of computer science Alevel. Worth it!
###################################################
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
################################################
# Question 3: Write a Python program to print the even numbers from a given list.
################################################
####################################################
#Question 4: Write a Python function that takes a number as a parameter and check the
number is prime or not
###################################################
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller adnanabedin. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $6.27. You're not tied to anything after your purchase.