9.5 - Challenges
Create a sub-program for each challenge below. It must match the provided dataflow.
You should test each sub-program fully to ensure it works as expected.
1 - Last character
Write a procedure that will display the last character in a word.
Data flow
IN: word
2 - Count text files
Write a function that counts how many text files are in an array.
files = [“names.txt”, “report.doc”, “happy.png”, “lyrics.txt”]
Output – There are 2 .txt files
Data flow
IN: file_array
OUT: txt_count
3 - Hide phone number
Write a procedure that will hide all digits in a phone number after the first three.
Enter phone number: 07946832669
079********
Data flow
IN: phone_num
4 - US to UK
Write a function that will accept a date in american format (mm/dd/yyyy) and return the date in uk format (dd/mm/yyyy).
Enter US date: 04/19/2021
UK date: 19/04/2021
Data flow
IN: us_date
OUT: uk_date
5 - Odd or even day
Write a procedure that will take a date in the form YYYY-MM-DD, extract the day, and display whether it is even or odd.
Data flow
IN: date
6 - String reversal
Write a function that will reverse a string:
Pizza -> azziP
Data flow
IN: string
OUT: reversed_string
7 - Palindrome check
Write a procedure that will take a word and check if it reads the same forwards and backwards.
Data flow
IN: word
8 - Longest surname
Write a procedure that will take an array of full names and display the longest surname.
Data flow
IN: full_names
9 - Vowel count
Write a procedure that will count how many vowels are in a string.
Data flow
IN: string
10 - ing
Write a function that will add ‘ing’ to the end of each string if it is not already present.
Read -> Reading
words = [“Read”, “Looking”, “Walk”, “Sitting”]
Data flow
IN: words
OUT: new_words
11 - Scramble
Write a function that will scramble a word into random positions.
Python -> yPnoht
Data flow
IN: word
OUT: scrambled_word