Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Please answer each question separately and write a new program for each required question. 1. Write pseudocode for a program that repeatedly prompts the user to enter a number or "x" to end. Upon...

1 answer below »
Please answer each question separately and write a new program for each required question.
1. Write pseudocode for a program that repeatedly prompts the user to enter a number or "x" to end.  Upon entering "x", the program displays the sum (total) of the numbers.
2. Write Python code that uses the following variable/data to print the desired output.
Your solution should involve looping through the data so that it would display appropriate output regardless of how many items are in the list.
For your convenience, the following line contains the data in a form that you can copy and paste:
data = [{'name': 'Adam', 'age': 57}, {'name': 'Betty', 'age': 21}, {'name': 'Carlos', 'age': 42}]
3. Write pseudocode (2 marks) and Python code (3 marks) for a function named "random_list".
The function should receive 3 parameters:
· "length", an intege
· "minimum", an intege
· "maximum", an intege
You may assume that the parameter values are of the expected type – you do not need to check that they are integers or 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".
Examples: XXXXXXXXXXrandom_list(5, 2, 8) should return a list of 5 random numbers between 2 and 8, such as [4, 8, 4, 5, 2]
andom_list(2, 1, 5) should return a list of 2 random numbers between 1 and 5, such as [2, 1]
andom_list(0, 1, 5) should return False, since "length" is less than 1
andom_list(2, 5, 1) should return False, since "minimum" is larger than "maximum"
4. 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 occu
ences 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)
· Spaces
· 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".
Examples:
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}
5. Write a Python program (8 marks) that implements the following requirements:
· Prompt the user to enter their name, age and email address.
· Make sure that:
· The name is at least one character long.
· The age is an integer (use exception handling for this) and at least 18.
· The email address contains a "@" character.
· If any of the criteria is not met, print “Invalid Data”.
· Otherwise, if all of the criteria is met:
· Store the three details in a dictionary using keys of "name", "age" and "email". Make sure that the age is stored as an integer.
· Write the dictionary to a file named "info.txt" in JSON format.
· Print "Data Saved".
Answered Same Day Jun 21, 2021

Solution

Neha answered on Jun 22 2021
141 Votes
1. Declare a list
Start a while loop
Ask the user to enter the numbe
Add all the elements in the list
Break while loop if user enters x
Print the sum
2. Prompt user to enter length
Prompt user to enter minimum numbe
Prompt user to enter maximum numbe
Create a method and pass length minimum and...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here