11.4 - Challenges
Create a solution for each challenge below. It must match any dataflow provided.
1 - Random numbers
Write a program that will save 100 random numbers (1-1000) in a text file.
2 - Times tables
Ask the user which times table they would like. Create that times table as a text file.
7 x 1 = 1
7 x 2 = 14
…
3 - Name split
Write a program that will ask the user for their full name. This string should then be split into forename and surname and saved into different text files.
Jane Smith
forename.txt – Jane
surname.txt – Smith
4 - Encrypted data
Write a program that asks the user to enter their password. The password should be encrypted using a Caesar cipher and then saved in a text file.
5 - Sentence splitter
Ask the user to enter a full sentence.
Split it into individual words and write each word on a new line in sentence.txt.
Example run
“I love programming”
sentence.txt
I
love
programming
6 - Average word length
Write a program that will ask the user to enter a sentence. The program should then calculate the average length of the words in the sentence.
“I love Computing Science”
Average length = 5.25 characters
7 - Journal
Write a program that lets the user write journal notes in the file ‘journal.txt‘ until they enter ‘stop‘. The exit comman ‘stop’ should not be written into the file.
Example run
“I love cats.”
“My birthday is soon!”
“stop”
journal.txt
I love cats.
My birthday is soon!