Question

Lab 1 Q1. Write a Python program with the following function building block. •All input values...

Lab 1

Q1. Write a Python program with the following function building block.

•All input values are to be taken fro

m the user.
•Ensure to check for possible error cases like mismatch of data type and input out of range,
for every function.

      Function 1:

countVowels(sentence) – Function that returns the count of vowels in a sentence.

Function 2:

Sum of all even numbers between two numbers, identify number of parameters  

Q2. Write a Python program that reads a text file called “perfumes.txt”. A sample of the file is provided below, you may add more details to the file. Each row has a perfume name and respective price. Your program must read the data from the file and identify the most expensive perfume in the list. Sample file is given below.

perfumes.txt
Gucci 415
Prada 435
Cartier 310
Hermes 553
Dior 386
Burberry 369

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def countVowels(sentence): count0 if not isinstance (sentence, str): return None for letter in sentence: if letter in aeiouA

def countVowels(sentence):

count = 0

if not isinstance(sentence, str):

return None

for letter in sentence:

if letter in "aeiouAEIOU":

count += 1

return count

def sumEven(f, t):

total = 0

if not isinstance(f, int) or not isinstance(t, int):

return None

for i in range(f, t+1):

if i % 2 == 0:

total += i

return total

print(countVowels("Cauliflower"))

print(countVowels(123))

print(sumEven(1, 10))

print(sumEven(1, 'qw'))

''' SAMPLE OUTPUT

5

None

30

None

'''

# Note: One question at a time please -- Policy of Chegg

Add a comment
Know the answer?
Add Answer to:
Lab 1 Q1. Write a Python program with the following function building block. •All input values...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a python program that does the following: takes as input from the user an English...

    Write a python program that does the following: takes as input from the user an English sentence calls the function vc_counter() that: takes a string argument counts the number of vowels and consonants in the string returns a dictionary of the counts, using the keys total_vowels and total_consonants Uses the return from vc_counter() to print the total vowels and consonants with appropriate descriptions. Example: Enter an English sentence: The quick brown fox's jump landed past the lazy dog! Total #...

  • Write a program in python that asks the user to input a sentence. The program will...

    Write a program in python that asks the user to input a sentence. The program will ask the user what two letters are to be counted. You must use a “for” loop to go through the sentence & count how many times the chosen letter appears in the sentence. You are not allowed to use python built-in function "count()" or you'll get a Zero! Output will show the sentence, the letter, and the number of times the letter appears in...

  • 1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write...

    1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write a Python program that prompts the user for a sentence, then replaces all the vowels in the sentence with an asterisk: '*' Your program should use/call your isVowel function from Assignment_Ch06-01. You can put the isVowel() function in a separate .py file, without the rest of the Ch06-01 code, and then import it. 6-01 CODE: def isVowel(x):     if x in "aeiouyAEIOUY":         return True     else:...

  • PYTHON 1- Write a program that creates a dictionary of the English words for all single...

    PYTHON 1- Write a program that creates a dictionary of the English words for all single digit numbers as follows: 1: 'one', 2: 'two', 3: 'three', etc. 2- Write a function called numConvert that receives the above dictionary and an integer number as parameters, and prints the English words for all the number's digits. For example, if the function receives 2311, it will print: two three one one 3- Test your program by adding a main function, which calls numConvert....

  • PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random...

    PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random integer numbers between 1 and 100. Then, print out the numbers between the two randomly generated ones using a while loop. The output is shown below. Output: a) start:4, end:14 4 5 6 7 8 9 10 11 12 13 14 b) start:15, end:20 15 16 17 18 19 20

  • 1. Write a Python program, in a file called concat_strings.py, that includes the following functions: orderedConcat,...

    1. Write a Python program, in a file called concat_strings.py, that includes the following functions: orderedConcat, a recursive function that takes two alphabetically-ordered strings and merges them, leaving the letters in alphabetical order. Note that the strings may be different lengths. a main method that inputs two ordered strings and calls the orderedConcat method to return a resulting merged, ordered string. Your main method should print the two input strings and the result. Note: You may not use any of...

  • (1)Write a program in Python that reads an arbitrary-length file. All lines that start with semicolons...

    (1)Write a program in Python that reads an arbitrary-length file. All lines that start with semicolons (;) or pound signs (#) should be ignored. All empty lines must be ignored Lines containing a string between square brackets are sections. Within each section, lines may contain numbers or strings. For each section, calculate the lowest, highest and modal (most common) number, and print it. In each section, also count all non-whitespace characters, and print that. Example input: ; this is a...

  • Task 1: Write a Python program that takes as input from the user the name of a file containing po...

    python code: Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the file consists of the postcode followed by a tab followed by a comma-separated list of locations that have that postcode. For example, the file Small.txt contains: 3015 Newport,South Kingsville,Spotswood 3016 Williamstown 3018 Altona,Seaholme 3019 3021 Albanvale,Kealba,Kings Park,St Albans Braybrook, Robinson Your program should create a list of postcode/location pairs with each pair stored...

  • Write a Python program to print all Perfect numbers between 1 to n. (Use any loop...

    Write a Python program to print all Perfect numbers between 1 to n. (Use any loop you want) Perfect number is a positive integer which is equal to the sum of its proper positive divisors. Proper divisors of 6 are 1, 2, 3. Sum of its proper divisors = 1 + 2 + 3 = 6. Hence 6 is a perfect number. *** proper divisor means the remainder will be 0 when divided by that number. Sample Input: n =...

  • In python 3, 1. Write a program that takes a number of credit hours and returns...

    In python 3, 1. Write a program that takes a number of credit hours and returns a classification as follows: 29 credits or less: freshman; 30-59 credits: sophomore; 60-89 credits: junior; 90+ credits: senior. 2. Use a loop to valid input such that users can only enter positive numbers. 3. Use a loop to allow the user to keep entering credit hours and receiving classifications until they quit. All code must be in a function. I suggest the following structure:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT