Condition Inside the print Function
Have you ever thought you could write the entire condition inside the print function and print the output based on the conditions? Here is how you can achieve this.
Python: 3.0    Anurag Rana    16 Jul 2021   0
Login to upvote
1
2
3
4
5
print("odd" if int(input("Enter a num: "))%2 else "even")

# output
# Enter a num: 33
# odd
Copy | Download as: .py file   PNG
Share on: FB   Twitter   LinkedIn   WA
©2021 - code108labs   Contributors   Hosted on DigitalOcean   Partner website: pythoncircle.com