Python pictographCalling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?Does Python have a string 'contains' substring method?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?
How can bays and straits be determined in a procedurally generated map?
I probably found a bug with the sudo apt install function
Why is the design of haulage companies so “special”?
How long does it take to type this?
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
Underlining section titles
Copenhagen passport control - US citizen
Is the month field really deprecated?
Shell script can be run only with sh command
What is the command to reset a PC without deleting any files
How to make payment on the internet without leaving a money trail?
N.B. ligature in Latex
Draw simple lines in Inkscape
Do Phineas and Ferb ever actually get busted in real time?
How to report a triplet of septets in NMR tabulation?
Can I interfere when another PC is about to be attacked?
Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?
Can I make popcorn with any corn?
How much RAM could one put in a typical 80386 setup?
declaring a variable twice in IIFE
How is this relation reflexive?
Why was the small council so happy for Tyrion to become the Master of Coin?
The magic money tree problem
"which" command doesn't work / path of Safari?
Python pictograph
Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?Does Python have a string 'contains' substring method?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This is my code for pictograph.
I want it to be like John = * * * * *
and why is there a "None" in the output?
print("Pictograph")
def J(a):
for i in range(1, a+1):
print("*", end=" ")
def C(b):
for j in range(1, b+1):
print("*", end=" ")
def Z(c):
for j in range(1, c+1):
print("*", end=" ")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John = ", J(x))
print("Chas = ", C(y))
print("Zed = ", Z(z))
and this is the output
Pictograph
Enter John's Number: >? 5
Enter Chas's Number: >? 4
Enter Zed's Number: >? 3
* * * * * John = None
* * * * Chas = None
* * * Zed = None
python python-3.x
add a comment |
This is my code for pictograph.
I want it to be like John = * * * * *
and why is there a "None" in the output?
print("Pictograph")
def J(a):
for i in range(1, a+1):
print("*", end=" ")
def C(b):
for j in range(1, b+1):
print("*", end=" ")
def Z(c):
for j in range(1, c+1):
print("*", end=" ")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John = ", J(x))
print("Chas = ", C(y))
print("Zed = ", Z(z))
and this is the output
Pictograph
Enter John's Number: >? 5
Enter Chas's Number: >? 4
Enter Zed's Number: >? 3
* * * * * John = None
* * * * Chas = None
* * * Zed = None
python python-3.x
2
I think you should return the value instead of printing it!
– lmiguelvargasf
Mar 9 at 3:43
add a comment |
This is my code for pictograph.
I want it to be like John = * * * * *
and why is there a "None" in the output?
print("Pictograph")
def J(a):
for i in range(1, a+1):
print("*", end=" ")
def C(b):
for j in range(1, b+1):
print("*", end=" ")
def Z(c):
for j in range(1, c+1):
print("*", end=" ")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John = ", J(x))
print("Chas = ", C(y))
print("Zed = ", Z(z))
and this is the output
Pictograph
Enter John's Number: >? 5
Enter Chas's Number: >? 4
Enter Zed's Number: >? 3
* * * * * John = None
* * * * Chas = None
* * * Zed = None
python python-3.x
This is my code for pictograph.
I want it to be like John = * * * * *
and why is there a "None" in the output?
print("Pictograph")
def J(a):
for i in range(1, a+1):
print("*", end=" ")
def C(b):
for j in range(1, b+1):
print("*", end=" ")
def Z(c):
for j in range(1, c+1):
print("*", end=" ")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John = ", J(x))
print("Chas = ", C(y))
print("Zed = ", Z(z))
and this is the output
Pictograph
Enter John's Number: >? 5
Enter Chas's Number: >? 4
Enter Zed's Number: >? 3
* * * * * John = None
* * * * Chas = None
* * * Zed = None
python python-3.x
python python-3.x
asked Mar 9 at 3:41
QwertyQwerty
93
93
2
I think you should return the value instead of printing it!
– lmiguelvargasf
Mar 9 at 3:43
add a comment |
2
I think you should return the value instead of printing it!
– lmiguelvargasf
Mar 9 at 3:43
2
2
I think you should return the value instead of printing it!
– lmiguelvargasf
Mar 9 at 3:43
I think you should return the value instead of printing it!
– lmiguelvargasf
Mar 9 at 3:43
add a comment |
3 Answers
3
active
oldest
votes
You are defining a function from which you are returning nothing. Change your functions to return a value. Also, did you know that you can repeat a string using the *
operator, for example 3 * 'a'
is 'aaa'
:
def J(a):
return (a * '* ')[:-1]
s[:-1]
means you are taking all the elements of a string s
but the last one.
You can also define a function to print your pattern, so you avoid code repetition.
def repeat_pattern(n):
return (n * '* ')[:-1]
Therefore, your code will be as follows:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", repeat_pattern(x))
print("Chas =", repeat_pattern(y))
print("Zed =", repeat_pattern(z))
Need spaces tho
– U9-Forward
Mar 9 at 3:46
1
@U9-Forwrd, thanks, and good catch!
– lmiguelvargasf
Mar 9 at 3:47
Your welcome, good solution now
– U9-Forward
Mar 9 at 3:48
oh okay. Thank you!
– Qwerty
Mar 9 at 3:48
@Qwerty, you're welcome
– lmiguelvargasf
Mar 9 at 3:59
add a comment |
The whole code could be just:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", ' '.join(x * '*'))
print("Chas =", ' '.join(y * '*'))
print("Zed =", ' '.join(z * '*'))
Or like @lmiguelvargasf's solution:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", (x * '* ')[:-1])
print("Chas =", (y * '* ')[:-1])
print("Zed =", (z * '* ')[:-1])
Both reproduce this (example output):
Pictograph
Enter John's Number: 5
Enter Chas's Number: 4
Enter Zed's Number: 3
John = * * * * *
Chas = * * * *
Zed = * * *
add a comment |
Since you're familar with loops, I would go with a solution that lets you add more data without having to add more code:
print("Pictograph")
data = []
for person in ['John', 'Chas', 'Zed']:
data.append((person, int(input(f"Enter person's Number: "))))
for person, number in data:
print(f"person =", *(['*'] * number))
USAGE
> python3 test.py
Pictograph
Enter John's Number: 13
Enter Chas's Number: 3
Enter Zed's Number: 20
John = * * * * * * * * * * * * *
Chas = * * *
Zed = * * * * * * * * * * * * * * * * * * * *
>
You might consider a tab character in the output to align the left-most stars.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073769%2fpython-pictograph%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are defining a function from which you are returning nothing. Change your functions to return a value. Also, did you know that you can repeat a string using the *
operator, for example 3 * 'a'
is 'aaa'
:
def J(a):
return (a * '* ')[:-1]
s[:-1]
means you are taking all the elements of a string s
but the last one.
You can also define a function to print your pattern, so you avoid code repetition.
def repeat_pattern(n):
return (n * '* ')[:-1]
Therefore, your code will be as follows:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", repeat_pattern(x))
print("Chas =", repeat_pattern(y))
print("Zed =", repeat_pattern(z))
Need spaces tho
– U9-Forward
Mar 9 at 3:46
1
@U9-Forwrd, thanks, and good catch!
– lmiguelvargasf
Mar 9 at 3:47
Your welcome, good solution now
– U9-Forward
Mar 9 at 3:48
oh okay. Thank you!
– Qwerty
Mar 9 at 3:48
@Qwerty, you're welcome
– lmiguelvargasf
Mar 9 at 3:59
add a comment |
You are defining a function from which you are returning nothing. Change your functions to return a value. Also, did you know that you can repeat a string using the *
operator, for example 3 * 'a'
is 'aaa'
:
def J(a):
return (a * '* ')[:-1]
s[:-1]
means you are taking all the elements of a string s
but the last one.
You can also define a function to print your pattern, so you avoid code repetition.
def repeat_pattern(n):
return (n * '* ')[:-1]
Therefore, your code will be as follows:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", repeat_pattern(x))
print("Chas =", repeat_pattern(y))
print("Zed =", repeat_pattern(z))
Need spaces tho
– U9-Forward
Mar 9 at 3:46
1
@U9-Forwrd, thanks, and good catch!
– lmiguelvargasf
Mar 9 at 3:47
Your welcome, good solution now
– U9-Forward
Mar 9 at 3:48
oh okay. Thank you!
– Qwerty
Mar 9 at 3:48
@Qwerty, you're welcome
– lmiguelvargasf
Mar 9 at 3:59
add a comment |
You are defining a function from which you are returning nothing. Change your functions to return a value. Also, did you know that you can repeat a string using the *
operator, for example 3 * 'a'
is 'aaa'
:
def J(a):
return (a * '* ')[:-1]
s[:-1]
means you are taking all the elements of a string s
but the last one.
You can also define a function to print your pattern, so you avoid code repetition.
def repeat_pattern(n):
return (n * '* ')[:-1]
Therefore, your code will be as follows:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", repeat_pattern(x))
print("Chas =", repeat_pattern(y))
print("Zed =", repeat_pattern(z))
You are defining a function from which you are returning nothing. Change your functions to return a value. Also, did you know that you can repeat a string using the *
operator, for example 3 * 'a'
is 'aaa'
:
def J(a):
return (a * '* ')[:-1]
s[:-1]
means you are taking all the elements of a string s
but the last one.
You can also define a function to print your pattern, so you avoid code repetition.
def repeat_pattern(n):
return (n * '* ')[:-1]
Therefore, your code will be as follows:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", repeat_pattern(x))
print("Chas =", repeat_pattern(y))
print("Zed =", repeat_pattern(z))
edited Mar 9 at 3:50
answered Mar 9 at 3:45
lmiguelvargasflmiguelvargasf
13.6k1489112
13.6k1489112
Need spaces tho
– U9-Forward
Mar 9 at 3:46
1
@U9-Forwrd, thanks, and good catch!
– lmiguelvargasf
Mar 9 at 3:47
Your welcome, good solution now
– U9-Forward
Mar 9 at 3:48
oh okay. Thank you!
– Qwerty
Mar 9 at 3:48
@Qwerty, you're welcome
– lmiguelvargasf
Mar 9 at 3:59
add a comment |
Need spaces tho
– U9-Forward
Mar 9 at 3:46
1
@U9-Forwrd, thanks, and good catch!
– lmiguelvargasf
Mar 9 at 3:47
Your welcome, good solution now
– U9-Forward
Mar 9 at 3:48
oh okay. Thank you!
– Qwerty
Mar 9 at 3:48
@Qwerty, you're welcome
– lmiguelvargasf
Mar 9 at 3:59
Need spaces tho
– U9-Forward
Mar 9 at 3:46
Need spaces tho
– U9-Forward
Mar 9 at 3:46
1
1
@U9-Forwrd, thanks, and good catch!
– lmiguelvargasf
Mar 9 at 3:47
@U9-Forwrd, thanks, and good catch!
– lmiguelvargasf
Mar 9 at 3:47
Your welcome, good solution now
– U9-Forward
Mar 9 at 3:48
Your welcome, good solution now
– U9-Forward
Mar 9 at 3:48
oh okay. Thank you!
– Qwerty
Mar 9 at 3:48
oh okay. Thank you!
– Qwerty
Mar 9 at 3:48
@Qwerty, you're welcome
– lmiguelvargasf
Mar 9 at 3:59
@Qwerty, you're welcome
– lmiguelvargasf
Mar 9 at 3:59
add a comment |
The whole code could be just:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", ' '.join(x * '*'))
print("Chas =", ' '.join(y * '*'))
print("Zed =", ' '.join(z * '*'))
Or like @lmiguelvargasf's solution:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", (x * '* ')[:-1])
print("Chas =", (y * '* ')[:-1])
print("Zed =", (z * '* ')[:-1])
Both reproduce this (example output):
Pictograph
Enter John's Number: 5
Enter Chas's Number: 4
Enter Zed's Number: 3
John = * * * * *
Chas = * * * *
Zed = * * *
add a comment |
The whole code could be just:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", ' '.join(x * '*'))
print("Chas =", ' '.join(y * '*'))
print("Zed =", ' '.join(z * '*'))
Or like @lmiguelvargasf's solution:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", (x * '* ')[:-1])
print("Chas =", (y * '* ')[:-1])
print("Zed =", (z * '* ')[:-1])
Both reproduce this (example output):
Pictograph
Enter John's Number: 5
Enter Chas's Number: 4
Enter Zed's Number: 3
John = * * * * *
Chas = * * * *
Zed = * * *
add a comment |
The whole code could be just:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", ' '.join(x * '*'))
print("Chas =", ' '.join(y * '*'))
print("Zed =", ' '.join(z * '*'))
Or like @lmiguelvargasf's solution:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", (x * '* ')[:-1])
print("Chas =", (y * '* ')[:-1])
print("Zed =", (z * '* ')[:-1])
Both reproduce this (example output):
Pictograph
Enter John's Number: 5
Enter Chas's Number: 4
Enter Zed's Number: 3
John = * * * * *
Chas = * * * *
Zed = * * *
The whole code could be just:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", ' '.join(x * '*'))
print("Chas =", ' '.join(y * '*'))
print("Zed =", ' '.join(z * '*'))
Or like @lmiguelvargasf's solution:
print("Pictograph")
x = int(input("Enter John's Number: "))
y = int(input("Enter Chas's Number: "))
z = int(input("Enter Zed's Number: "))
print("John =", (x * '* ')[:-1])
print("Chas =", (y * '* ')[:-1])
print("Zed =", (z * '* ')[:-1])
Both reproduce this (example output):
Pictograph
Enter John's Number: 5
Enter Chas's Number: 4
Enter Zed's Number: 3
John = * * * * *
Chas = * * * *
Zed = * * *
answered Mar 9 at 3:45
U9-ForwardU9-Forward
18k51744
18k51744
add a comment |
add a comment |
Since you're familar with loops, I would go with a solution that lets you add more data without having to add more code:
print("Pictograph")
data = []
for person in ['John', 'Chas', 'Zed']:
data.append((person, int(input(f"Enter person's Number: "))))
for person, number in data:
print(f"person =", *(['*'] * number))
USAGE
> python3 test.py
Pictograph
Enter John's Number: 13
Enter Chas's Number: 3
Enter Zed's Number: 20
John = * * * * * * * * * * * * *
Chas = * * *
Zed = * * * * * * * * * * * * * * * * * * * *
>
You might consider a tab character in the output to align the left-most stars.
add a comment |
Since you're familar with loops, I would go with a solution that lets you add more data without having to add more code:
print("Pictograph")
data = []
for person in ['John', 'Chas', 'Zed']:
data.append((person, int(input(f"Enter person's Number: "))))
for person, number in data:
print(f"person =", *(['*'] * number))
USAGE
> python3 test.py
Pictograph
Enter John's Number: 13
Enter Chas's Number: 3
Enter Zed's Number: 20
John = * * * * * * * * * * * * *
Chas = * * *
Zed = * * * * * * * * * * * * * * * * * * * *
>
You might consider a tab character in the output to align the left-most stars.
add a comment |
Since you're familar with loops, I would go with a solution that lets you add more data without having to add more code:
print("Pictograph")
data = []
for person in ['John', 'Chas', 'Zed']:
data.append((person, int(input(f"Enter person's Number: "))))
for person, number in data:
print(f"person =", *(['*'] * number))
USAGE
> python3 test.py
Pictograph
Enter John's Number: 13
Enter Chas's Number: 3
Enter Zed's Number: 20
John = * * * * * * * * * * * * *
Chas = * * *
Zed = * * * * * * * * * * * * * * * * * * * *
>
You might consider a tab character in the output to align the left-most stars.
Since you're familar with loops, I would go with a solution that lets you add more data without having to add more code:
print("Pictograph")
data = []
for person in ['John', 'Chas', 'Zed']:
data.append((person, int(input(f"Enter person's Number: "))))
for person, number in data:
print(f"person =", *(['*'] * number))
USAGE
> python3 test.py
Pictograph
Enter John's Number: 13
Enter Chas's Number: 3
Enter Zed's Number: 20
John = * * * * * * * * * * * * *
Chas = * * *
Zed = * * * * * * * * * * * * * * * * * * * *
>
You might consider a tab character in the output to align the left-most stars.
answered Mar 9 at 5:31
cdlanecdlane
20k21245
20k21245
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073769%2fpython-pictograph%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
I think you should return the value instead of printing it!
– lmiguelvargasf
Mar 9 at 3:43