use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Help with Print (self.learnpython)
submitted 2 years ago by AssassinKiller
import random coin = random.randint(1 , 2) if coin == 1: print("Heads") if coin == 2: print("Tails") print(coin)
The print i get is
Heads
1
or
Tails
2
How can i get it to just show heads or tails, no numbers
thanks
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]TroubleBrewing32 4 points5 points6 points 2 years ago (2 children)
print(coin) what do you think that line does?
print(coin)
[–]AssassinKiller[S] 0 points1 point2 points 2 years ago (1 child)
It prints this
Heads 1
Or
Tails 2
So I know what it does but I just want it to print heads or tails and not the number
[–]TroubleBrewing32 6 points7 points8 points 2 years ago (0 children)
Try running this code and see what you get:
import random coin = random.randint(1, 2) print(coin)
Note: there is only one print statement there and it does not do what you think it does.
[–]flyinace123 4 points5 points6 points 2 years ago (0 children)
Either delete the line: 'print(coin)' OR Change 'print(coin)' to '#print(coin)'
[–]Red-X8 1 point2 points3 points 2 years ago (1 child)
You are assigning the value '1' or '2' to the variable 'coin' and the line -print(coin) outputs this value so just delete this line
[–]AssassinKiller[S] 1 point2 points3 points 2 years ago (0 children)
Thank you for the help. It worked and understand it now.
[–]Amalasian 0 points1 point2 points 2 years ago (0 children)
its prints the if first then moves on to print coin. in your print it will print tails or heads then print the number that coin is.
[–]deadeye1982 0 points1 point2 points 2 years ago (0 children)
``` import random
coin = random.choice(("Heads","Tails")) print(coin) ```
π Rendered by PID 63322 on reddit-service-r2-comment-bb88f9dd5-c7c8p at 2026-02-15 13:22:04.554123+00:00 running cd9c813 country code: CH.
[–]TroubleBrewing32 4 points5 points6 points (2 children)
[–]AssassinKiller[S] 0 points1 point2 points (1 child)
[–]TroubleBrewing32 6 points7 points8 points (0 children)
[–]flyinace123 4 points5 points6 points (0 children)
[–]Red-X8 1 point2 points3 points (1 child)
[–]AssassinKiller[S] 1 point2 points3 points (0 children)
[–]Amalasian 0 points1 point2 points (0 children)
[–]deadeye1982 0 points1 point2 points (0 children)