Python Homework

User Generated

FZFN3

Programming

CS 118

Description

Python Homework


Create a script called homework7YN.py (where YN is your initials)

  • Write a function countLetters that expects 2 input arguments: a sentence and a letter. The function will check the number of times the letter occurs in the sentence. The function counterLetter should return a number (number of times the letter occurred in the sentence).
  • Write a function promptUser that prompts the user for a sentence and a letter. In promptUser, call countLetter with the sentence and letter you read in from the user. Save the value returned from the function and use in to append to a file count.txt.

When you run the program it should look like.......(things you need to type are in red, text file contents in green). Submit both homework7YN.py and in the comments on Canvas list any global variable names in the program and local variable names in the program.

>>promptUser( )
Enter a sentence:Have a nice day!
Enter a letter:a


Open file count.txt and see:
3 a's found in Have a nice day!

------------------------------------------------
>>promptUser( )
Enter a sentence:CS118 is a great class!
Enter a letter:s

Open file count.txt and see:
3 a's found in Have a nice day!
3 s's found in CS118 is a great class!

--------------------------------------------------
>>promptUser( )
Enter a sentence:This is fun.
Enter a letter:u


Open file count.txt and see:
3 a's found in Have a nice day!
3 s's found in CS118 is a great class!
1 u's found in This is fun.

--------------------------------------------------
>>scriptYN
Enter a sentence:I can't wait for summer.
Enter a letter:z


Open file count.txt and see:
3 a's found in Have a nice day!
3 s's found in EGR115 is a great class!
1 u's found in This is fun.
0 z's found in I can't wait for summer.

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Here is your program, I te...


Anonymous
Just what I needed. Studypool is a lifesaver!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Similar Content

Related Tags