• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 5 pages
Summary

Summary Computer Science Alevel Theory/Programming revision Notes

Document preview thumbnail
Preview 2 out of 5 pages

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!

Content preview

###################################################
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
###################################################

Document information

Study Level
Subject
Uploaded on
February 15, 2023
Number of pages
5
Written in
2022/2023
Type
Summary
$7.29

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
2
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions