1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vesna_86 [32]
3 years ago
6

In this exercise we will practice using loops to handle collections/containers. Your job is to write a program that asks the use

r to enter a sentence, then it counts and displays the occurrence of each letter.
Note: your program should count the letters without regard to case. For example, A and a are counted as the same.
Here is a sample run:
Enter a sentence: It's a very nice day today!
a: 3 times
c: 1 times
d: 2 times
e: 2 times
i: 2 times
n: 1 times
o: 1 times
r: 1 times
s: 1 times
t: 2 times
v: 1 times
y: 3 times
Notes:
The purpose of this problem is to practice using loops and collections/containers/strings.
Please make sure to submit a well-written program. Good identifier names, useful comments, and spacing will be some of the criteria that will be used when grading this assignment.
This assignment can be and must be solved using only the materials that have been discussed in class: loops, the index system, strings, lists and/or dictionaries. Do not look for or use alternative methods that have not been covered as part of this course.
How your program will be graded:
correctness: the program performs calculations correctly: 40%
complies with requirements (it properly uses loops, and containers/strings): 40%
code style: good variable names, comments, proper indentation and spacing : 20%
Language is python 3
Computers and Technology
1 answer:
kati45 [8]3 years ago
5 0

Answer:

In Python:

chars = 'abcdefghijklmnopqrstuvwxyz'

letter = input("Sentence: ")

for i in range(len(chars)):

   count = 0

   for j in range(len(letter)):

       if chars[i] == letter[j].lower():

           count = count + 1

   if count > 0 :

       print(chars[i]+": "+str(count)+" times")

Explanation:

This initializes the characters of alphabet from a-z

chars = 'abcdefghijklmnopqrstuvwxyz'

This prompts the user for sentence

letter = input("Sentence: ")

This iterates through the initialized characters

for i in range(len(chars)):

This initializes count to 0

   count = 0

This iterates through the input sentence

   for j in range(len(letter)):

This compares the characters of the sentence with alphabet a-z

       if chars[i] == letter[j].lower():

If there is a match, count is incremented by 1

           count = count + 1

If there is an occurrence of character,

   if count > 0 :

The character and its count is printed

       print(chars[i]+": "+str(count)+" times")

You might be interested in
To join a social network you create an avatar true or false
svp [43]
False because not all social media webstites provide avatars
7 0
3 years ago
Read 2 more answers
Write a program which asks the user to enter N numbers. The program will print out their average. Try your program with the foll
Likurg_2 [28]

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

   // variables

int n;

double average,sum=0,x;

cout<<"enter the Value of N:";

// read the value of N

cin>>n;

cout<<"enter "<<n<<" Numbers:";

// read n Numbers

for(int a=0;a<n;a++)

{

   cin>>x;

   // calculate total sum of all numbers

   sum=sum+x;

}

// calculate average

average=sum/n;

// print average

cout<<"average of "<<n<<" Numbers is: "<<average<<endl;

return 0;

}

Explanation:

Read the total number from user i.e "n".Then read "n" numbers from user with for loop and sum them all.Find there average by dividing the sum with n.And print the average.

Output:

enter the Value of N:5

enter 5 Numbers:20.5 19.7 21.3 18.6 22.1

average of 5 Numbers is: 20.44

7 0
3 years ago
Write a program that declares and initializes a variable representing the weight in milligrams from the keyboard. The program di
Burka [1]

Answer:

weight = int(input("Enter weight in milligrams: "))

kilograms = int(weight / 1000000)

grams = int((weight - (kilograms * 1000000)) / 1000)

milligrams = weight - ((kilograms * 1000000) + (grams * 1000))

print("{} milligrams are equivalent to {} kilogram(s), {} gram(s), and {} milligram(s)".format(weight, kilograms, grams, milligrams))

Explanation:

*The code is in Python.

Ask the user to enter the weight and set it to the variable weight

Calculate the kilograms, divide the weight by 1000000 and cast the result to the int (If the weight is 1050042, kilograms would be 1050042/1000000 = 1)

Calculate the grams, subtract the kilograms from the weight, divide it by 1000 and cast the result to the int (If the weight is 1050042, grams would be int((1050042 - (1 * 1000000)) / 1000) = 50)

Calculate the milligrams, subtract the kilograms and grams from the weight (If the weight is 1050042, milligrams would be 1050042 - ((1 * 1000000) + (50 * 1000)) = 42)

Print the weight, kilograms, grams, and milligrams in the required format

3 0
2 years ago
What happens if you never confirm your facebook account?
OleMash [197]
Nothing, it will just keep sending you annoying notifications that become more and more frequent, i would just confirm it if i were you
5 0
3 years ago
Which of the following situations best illustrates the process of authentication?a.A Web site sets users' passwords to expire ev
Paladinen [302]

Using an electronic signature on official documentation best illustrates the process of authentication

Further explanation:

The continuous rise of Electronic signatures has made it easier for people to accept signed documents by email or through electronic devices. One good example of electronic signatures is the implementation of digital signatures which broadly encompasses many types of electronic signatures out there. Digital signatures are unique to each signer and follow a standard authentication protocol called PKI. PKI use mathematical algorithms to generate what are known as private and public keys.

A good example is Bob and Jane. Jane sends an eSignature document using her private keys. Bob receives this document with an attached copy of Jane’s public key. The signature will be considered valid if the public key decrypts the signature correctly.

Learn more about eSignatures and electronic signatures.

brainly.com/question/8776017

#LearnWithBrainly

7 0
3 years ago
Other questions:
  • Why is it so important that you know how much traffic dfs replication requires?
    13·2 answers
  • blank affect your vision because your eye muscles are tired along with the rest of your body and is difficult to focus
    11·2 answers
  • How does technology helps save the environment?​
    6·1 answer
  • Given a Fahrenheit value temperatureFahrenheit, write a statement that assigns temperatureCelsius with the equivalent Celsius va
    9·1 answer
  • How can officers in the armed services receive college educations? Select the best answer choice. A. All of the answers are corr
    11·1 answer
  • A computer technician is responding to a call about a printer that is causing streaks to appear on every printout. Which of the
    5·1 answer
  • The process of identifying and removing logical errors and runtime errors is called ..............
    5·2 answers
  • Under the Home tab, controls for aligning text and objects can be found in the
    5·2 answers
  • How does naming affect a variable’s creation and use?
    6·1 answer
  • C program how to input this? ​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!