CompSci101-Assignment01
QUESTION2(5MARKS)
Writeaprogramwhichgeneratesarandompasswordmadeupofsevenlettersfollowedbyathreedigit
numberbetween101and999inclusive.Ofthesevenrandomlettersthefourlettersatevenpositions
(i.e.,0,2,4,6)shouldbevowelsandthethreelettersatoddpositions(i.e.,1,3,5)shouldbeconsonants,
e.g.,ukoripa251,ewabuzo812,eyupabo288.Thiswayofcreatingthewordmakestheword
pronounceable.Belowaretheconsonantsandvowelswhichareallowedfortherandomletterspartofthe
password.Pastethesetwostatementsintoyourprogram.
Due: 4:30pm,Wednesday18thJanuary2017.
Worth: Thisassignmentismarkedoutof25andisworth2.5%ofyourfinalmark.
Topicscovered:
•
•
•
•
•
Arithmeticoperators,
Printingoutput,
Manipulatingstringobjects,
Generatingrandomnumbers,
Gettinguserinput
consonants = "bcdfghjklmnprstvwz"
vowels = "aeiou"
NOTE:Forthisassignmentyoushouldnotuseifstatementsorloops.
NOTE:Eachofyourfilesmustincludeadocstringatthetopofthefilecontainingyourname,username,
StudentIDNumberandadescriptionoftheprogram.Submitthefilescontainingyourprogramsusingthe
AssignmentDropbox:
https://adb.auckland.ac.nz/Home/
NOTE:YoucansubmitasmanytimesasyouwishbuteverytimeyousubmityouneedtosubmitALLfive
files('YourUsernameA1Q1.py', 'YourUsernameA1Q2.py', 'YourUsernameA1Q3.py',
'YourUsernameA1Q4.py', 'YourUsernameA1Q5.py')evenifyouhavenotdonethecodefor
thequestion.
QUESTION1(5MARKS)
Writeaprogramwhichprintsathreewordsentence,onewordperline,insidearectangularframeof
stars.Thefirstlineofyourprograminitialisesthesentence variabletobeastringmadeupofexactly
threewordseachseparatedbyasinglespace,e.g.,
Belowarethreeexampleoutputsproducedbyexecutingthecompletedprogramthreetimes(using
differentsentences):
***********
*************
***********
***********
*************
***********
* Thought *
* Learn
*
* Life
*
* is
*
* something *
* is
*
* free
*
* new
*
* awesome *
***********
*************
***********
***********
*************
***********
Includethisprograminamodule(file)named'YourUsernameA1Q1.py',e.g.,afer023A1Q1.py.
QUESTION3(5MARKS)
Writeaprogramwhichaddstwotimes(inhours,minutesandseconds)together.Thetimesinthis
programusea24hourclock,e.g.,15:23:15is23minutesand15secondspast3pm.Thefirsttwolinesof
yourprograminitialisethevariablesinthefollowingway(youwillneedtochangethevaluesassignedto
thesetwovariableswhenyoutestyourprogram):
time1_str = "06:55:12"
time2_str = "21:53:50"
Thefinaltimeshouldalwaysbeatimebetween00:00:00and23:59:59.Thetimestringstobeaddedand
thefinaltimealwayshavetheform"hh:mm:ss",i.e.,asingledigithour,minuteorsecondhasa"0"infront
ofit.Belowarefourexampleoutputsusingthecompletedprogram(usingdifferentvariablevalues).Your
programmustgivethecorrectoutputinthesameformatastheoutputsinthefourexamplesbelow:
26:35:12 + 01:03:01 = 03:38:13
06:55:12 + 21:53:50 = 04:49:02
06:05:12 + 01:23:51 = 07:29:03
00:01:01 + 23:58:59 = 00:00:00
Includethisprograminamodule(file)named'YourUsernameA1Q3.py',e.g.,afer023A1Q3.py.
CompSci101,SummerSemester,2017
Password: isavonu999
Includethisexerciseinamodule(file)named'YourUsernameA1Q2.py',e.g.,afer023A1Q2.py.
sentence = "Thought is free"
Theprogramprints"Password: " followedbytherandompassword.Belowarethreeexample
outputsproducedbyexecutingthecompletedprogramthreetimes:
Password: agewilu233
Password: ejiguka900
-1-
AssignmentOne
CompSci101,SummerSemester,2017
-2-
AssignmentOne
QUESTION4(5MARKS)
Inthe1840s,Morsecodewasdevelopedinordertosendinformationlongdistancesthroughwiresusinga
telegraphicdevice.InMorsecodeeachletterofthealphabetcorrespondstoacombinationofdotsand
dashes(called'dit'and'dah'andsometimesthe't'from'dit'isdropped),e.g.,'SOS'is'... --...' inMorsecodeanditsoundslike'Di-Di-DitDah-Dah-DahDi-Di-Dit'whensenttelegraphically.Ifthe
durationofadotistakentobeoneunitthenthatofadashisthreeunits.
WriteaprogramwhichtranslatesafourletterwordofuppercasecharactersintoitsequivalentMorse
code.Pastethefollowingtwostatementsintoyourprogram:
morse_codes = "A .B -... C -.-. D -.. E .
F ..-. G --. H .... I
..
J .--- K -.- L .-.. M -N -.
O --- P .--. Q --.- R .-. S
... T U ..- V ...- W .-- X -..- Y -.-- Z --.. "
word = 'COME'
Note:thateachuppercaseletterofthemorse_codesstringisfollowedbyasingleblankspacefollowed
byexactly5characterscontainingtheMorsecodeforthatletter(theMorsecodeispaddedwithblank
spacessothatitisalwaysexactly5charactersinlength).
current_total = 0
Belowaretwoexampleoutputsusingthecompletedprogram(theuserinputisshowninblue).Your
programmustgivetheoutputinthesameformatastheoutputsinthetwoexamplesbelow.Notethat
therowsof"*"symbolshavealengthof26.
**************************
REACH 100 IN THREE ROUNDS!
**************************
**************************
REACH 100 IN THREE ROUNDS!
**************************
Theprogramprintstwolinesofoutput,thefourletterwordwhichistobetranslatedandeachofthe
MorsecodesforthefourlettersofthewordwithinsinglequoteswhereeachletteroftheMorsecodeis
printedtakingupEXACTLY6spaces(paddedwithblankspacesontherighthandside).
Belowarethreeexampleoutputsproducedbyexecutingthecompletedprogramthreetimeswiththree
differentwords.Yourprogrammustgivethecorrectoutputinthesameformatastheoutputsinthethree
examplesbelow:
word: COME
Morse code: '-.-.
QUESTION5(5MARKS)
Writeaprogramwhichimplementsadicegame.Theaimofthegameistoreachascoreascloseas
possibleto100(butnotover100)inthreerounds.Eachroundconsistsofthrowingfiverandomdice,the
userthenchoosestwoofthedicevalueswherethetwodicevalueschosenformatwodigitscorewhichis
addedtotheuser'scurrenttotal,e.g.,iftheuserfirstchoosesadicewiththevalue3andthenadicewith
thevalue5,35isaddedtotheuser'stotal(thefirstdicechosenisthetensdigitandtheseconddice
chosenistheunitsdigit).Therandomdicearedisplayedwithonespacebetweeneachdice,e.g.,
Your dice: 3 5 3 4 1
andtochoosethedicetheuserentersanumber(1,2,3,4or5)indicatingwhichofthefivedicetheywish
tochoose.Thisprocessisrepeatedthreetimes.Belowisthestatementwhichinitialisestheuser'scurrent
score:
word: JUMP
Morse code: '.---
..-
--
.--.
word: HELP
Morse code: '....
---
--
.
'
Round 1
Your dice: 3 3 6 2 5
Tens? 1
Units? 4
Dice value: 32
Your current total: 32
Round 2
Your dice: 1 5 4 5 6
Tens? 1
Units? 5
Dice value: 16
Your current total: 48
'
.
.-..
.--.
'
Round 3
Your dice: 5 2 2 3 3
Tens? 1
Units? 2
Dice value: 52
**************************
Your final score: 100
**************************
Round 1
Your dice: 4 1 3 4 1
Tens? 1
Units? 4
Dice value: 44
Your current total: 44
Round 2
Your dice: 5 2 4 4 4
Tens? 3
Units? 1
Dice value: 45
Your current total: 89
Round 3
Your dice: 4 3 2 5 3
Tens? 3
Units? 5
Dice value: 23
**************************
Your final score: 112
**************************
Includethisprograminamodule(file),named'YourUsernameA1Q4.py',e.g.,afer023A1Q4.py.
Includethisprograminamodule(file),named'YourUsernameA1Q5.py',e.g.,afer023A1Q5.py.
CompSci101,SummerSemester,2017
-3-
AssignmentOne
CompSci101,SummerSemester,2017
-4-
AssignmentOne
© Copyright 2026 Paperzz