100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Summary Computer Science Alevel Theory/Programming revision Notes

Rating
-
Sold
-
Pages
5
Uploaded on
15-02-2023
Written in
2022/2023

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!

Show more Read less









Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
February 15, 2023
Number of pages
5
Written in
2022/2023
Type
Summary

Subjects

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
###################################################
£4.79
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
adnanabedin

Get to know the seller

Seller avatar
adnanabedin Queen Mary, University of London
View profile
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
2 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

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

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight 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 smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions