Part 1: Write pseudocode and code for a function named "random_list".

The function should receive 3 parameters:
"length", an integer
"minimum", an integer
"maximum", an integer

Assume that the parameter values are integers– no need to convert them to integers.

If "length" is smaller than 1 or if "minimum" is bigger than "maximum", the function should return the boolean value of False.  Otherwise, the function should return a list of "length" random integers between "minimum" and "maximum".

random_list(5, 2, 8) should return a list of 5 random numbers between 2 and 8, such as [4, 8, 4, 5, 2]
random_list(2, 1, 5) should return a list of 2 random numbers between 1 and 5, such as [2, 1]
random_list(0, 1, 5) should return False, since "length" is less than 1
random_list(2, 5, 1) should return False, since "minimum" is larger than "maximum"

Part 2:
Write pseudocode (2 marks) and Python code (5 marks) for a function named "count_chars".

The function should receive 1 parameter:
"text", a string

You may assume that the parameter value is of the expected type – you do not need to check that it is a string or convert it to a string.

The function's purpose is to count occurrences of different types of characters in "text" and return the information as a dictionary.  The function must determine how many of the following types of characters are in "text":

Letters (lowercase and uppercase)
Numbers (i.e. the digits 0-9)
Other characters (anything that is not a letter, number or space)

The function must return the four totals in a dictionary with keys of "letters", "numbers", "spaces" and "others".

count_chars('Abc123') should return {'letters': 3,  'numbers': 3,  'spaces': 0, 'others': 0}
count_chars('Hello, world!') should return {'letters': 10,  'numbers': 0,  'spaces': 1, 'others': 2} count_chars('') should return {'letters': 0,  'numbers': 0,  'spaces': 0, 'others': 0}

Part 3:
Write a program that prompts user to enter info and store it in a text file in JSON format.

prompt user to enter name, age, email.
make sure the name is minimum one character
that age is an integer and minum 18
if criteria not met, print "invalid data"
if all met: store three details in dictionary using keys "name" "age" "email". Age is stored as integer.
Dictionary stored to a file name into.txt
print data saved if done.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import random

# PSEUDOCODE - random list

# check if the length of the list is less than 1
# check if the minimum is greater than maximum
# if any of the above conditions are met, return False - exit function
# otherwise, initialize an empty list that will be used to store random integers
# use for (or while) loop to generate a random number in each iteration
# append a random number to the list

def random_list(length, minimum, maximum):
    if length < 1 or minimum > maximum:
       return False

    L = list()
    for _ in range(length):
       random_number = random.randint(minimum, maximum)
    return L

# PSEUDOCODE - count_chars...

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats