100% satisfaction guarantee Immediately available after payment Read online or as PDF No strings attached 4.6 TrustPilot
logo-home
Exam (elaborations)

Coding Practice Questions

Rating
-
Sold
-
Pages
2
Grade
A+
Uploaded on
29-10-2022
Written in
2021/2022

Coding Questions which give you a starting code and then asks you to tweak the code to get different results that are fundamental for the exam. The questions start simple yet by the end they get a lot more complex.

Institution
Course

Content preview

Coding Practice
Objective 5:
Understand how to use arithmetic operations and random numbers
In this objective you learn how to perform mathematical calculations using power, modulus and
integer division. Random numbers allow for some unpredictability which is useful for games.

Tasks
1. Try entering the following program to see how arithmetic operators work:

#Get user input
number1=int(input("Enter first number: "))
number2=int(input("Enter second number: "))

#Make calculations
power_of_result = number1 ** number2
division_result = number1 / number2
integer_division_result = number1 // number2
modulus_result = number1 % number2

#Output results
print()
print(number1,"to the power of",number2,"is",power_of_result)
print(number1,"divided by",number2,"is",division_result)
print(number1,"divided
by",number2,"is",integer_division_result)
print(number1,"divided by",number2,"has a remainder
of",modulus_result)


2. Try entering the following commands and see what happens:

import random
#Roll the dice
random_number = random.randint(1,6)
print("You rolled a",random_number)

Note import random at the top of the program. For Python to generate a random
number it needs the randint method which is not in the default set of commands Python
understands. Instead it is defined in a library of methods, called ‘random’. You can import
additional commands from libraries into your program.


3. Change the program so that it outputs a 10 sided dice.


4. Change the program so the user can choose to roll a 4, 6 or 12 sided dice.

Written for

Institution
Study
Course
School year
3

Document information

Uploaded on
October 29, 2022
Number of pages
2
Written in
2021/2022
Type
Exam (elaborations)
Contains
Answers

Subjects

$4.81
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Read online or as PDF
No strings attached

Get to know the seller
Seller avatar
NittenMenin

Get to know the seller

Seller avatar
NittenMenin
Follow You need to be logged in order to follow users or courses
Sold
1
Member since
3 year
Number of followers
1
Documents
19
Last sold
1 year ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

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

Frequently asked questions