• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 5 páginas
Resumen

Summary Computer Science Alevel Theory/Programming revision Notes

Document preview thumbnail
Vista previa 2 fuera de 5 páginas

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!

Vista previa del contenido

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

Información del documento

Nivel de Estudio
Tema
Subido en
15 de febrero de 2023
Número de páginas
5
Escrito en
2022/2023
Tipo
Resumen
$7.29

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
0
Artículos
2
Última venta
-



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes