Question with problem

For students who are taking a programming course, may be restricted in what they can use, or have other unusual limitations on solving their task.

Question with problem

Postby axcental » Tue Sep 13, 2016 11:22 pm

I have a code that when I run it, it prints out 3 times instead of once. How would I fix this?
Here is my code:
Code: Select all
def bargraph(name,number):
    print("Romney"," "*5,"46", " ", "*"*46)
    print("Gingrich"," "*3,"32"," ", "*"*32)
    print("Santorum"," "*3,"13"," ", "*"*13)
    print("Paul"," "*8,"7"," ", "*"*7)
    print("Other"," "*7,"1"," ", "*")
format('3d')

bargraph("Romney", 46)
bargraph("Gingrich", 32)
bargraph("Santorum", 13)
bargraph("Paul", 7)
bargraph("Other", 1)
Last edited by Yoriz on Tue Sep 13, 2016 11:32 pm, edited 1 time in total.
Reason: First post lock. Added code tags.
axcental
 
Posts: 2
Joined: Tue Sep 13, 2016 11:20 pm

Re: Question with problem

Postby Yoriz » Tue Sep 13, 2016 11:34 pm

What prints out 3 times instead of once?
What is your expected output compared to the output you actually are getting?
Why does your function take a name and number and not use them?
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Yoriz
 
Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Question with problem

Postby axcental » Wed Sep 14, 2016 1:59 am

Basically what prints out is a graph of votes, but it prints out 3 times instead of just once.
axcental
 
Posts: 2
Joined: Tue Sep 13, 2016 11:20 pm

Re: Question with problem

Postby Ofnuts » Wed Sep 14, 2016 5:24 am

Your function doesn't use its parameters and prints votes for all candidates. Then you call that function once per candidate. You should fix you function so that if prints only one line of the graph for a given name and vote count. Then you call it for each candidate.
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987

Re: Question with problem

Postby Yoriz » Wed Sep 14, 2016 6:50 am

axcental wrote:Basically what prints out is a graph of votes, but it prints out 3 times instead of just once.

The code prints 5 things, 5 times.
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Yoriz
 
Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Question with problem

Postby Ofnuts » Wed Sep 14, 2016 8:24 am

Yoriz wrote:
axcental wrote:Basically what prints out is a graph of votes, but it prints out 3 times instead of just once.

The code prints 5 things, 5 times.

The OP is a beginner. S/he doesn't know what "accuracy" means. Yet. :)
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987


Return to Homework

Who is online

Users browsing this forum: Google [Bot] and 3 guests