Python Programming — Conditional Statement

x = float (input ('Enter a number = '));if(x >= 10):
print ('Congratulations, the number you entered is correct')
Enter a number = 11Congratulations, the number you entered is correct
Enter a number = 9#program not executed
x = int(input('enter the value of x: '))
y = int(input('enter the value of y: '))
if x < y:
print('x is less than y')
else:
print('x is more than y')
print('x={}, y={}'.format(x, y))
enter the value of x: 5
enter the value of y: 2
x is more than y
x=5, y=2
enter the value of x: 5
enter the value of y: 5
x is more than y
x=5, y=5
x = int(input('enter the value of x: '))
y = int(input('enter the value of y: '))
if x < y :
print('x is less than y')
elif x > y :
print('x is more than y')
else :
print('x is equal to y')

print('x={}, y={}'.format(x, y))
enter the value of x: 5
enter the value of y: 5
x is equal to y
x=5, y=5
  • The conditional statement starts from the first, when a statement is fulfilled, the statement command will be executed and the conditional statement will be terminated
  • Conditional expressions start with the syntax if
  • Conditional expression is a conditional statement that is tested which can contain mathematical operators, functions, and logic
  • Each conditional expression ends with a colon :
  • Every conditional expression has a command code in writing indents
  • Conditional_expression_1 is the first conditional statement with the command command_1
  • The second and so on conditional expressions start with the syntax elif
  • Conditional_expression_2 is the second conditional statement with the command command_2
  • Conditional_expression_3 is the third conditional statement with the command command_3
  • Alternative conditions are written ending with the else syntax:
  • alternative_command is an alternative command, used when all conditional conditions are not met
  • if you buy it will display the number of items purchased and the total price of the item
  • If after buying the remaining money will be displayed in the wallet
  • If you can’t buy an item, it will show that you have less money
burger_price = 5
money = 20
input_count = input('How many burgers do you want : ')
count = int(input_count)
total_price = burger_price * count
print('You will buy ' + str(count) + ' burgers')
print('Total price is ' + str(total_price) + ' dolars')

if money > total_price:
print('You have bought ' + str(count) + ' burgers')
print('your money is left ' + str(money - total_price) + ' dolar')
elif money == total_price:
print('You have bought ' + str(count) + ' burgers')
print('your wallet is empty')
else:
print('your money is not enough')
print('you cant buy that many burgers')
#if can buy a burgerHow many burgers do you want : 3
You will buy 3 burgers
Total price is 15 dolars
You have bought 3 burgers
your money is left 5 dolar
#if can't buy a burger
How many burgers do you want : 10
You will buy 10 burgers
Total price is 50 dolars
your money is not enough
you cant buy that many burgers

--

--

--

NIM (K3521056), EMAIL : bluerejet1330@gmail.com, UNIVERSITAS SEBELAS MARET

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why Lazy Evaluation enhances performance and makes Apache Spark distinct?

Where To Get A Dedicated Development Team — Denmark

Serato Scratch Live Skin For Virtual Dj Download Zip

Multi-Region Apache Cassandra on Azure Kubernetes Service with the K8ssandra Operator (Part One)

Rails G Resource: Friend or Foe?

Sharing via RWMutex

Revise GIT, CAP theorem and MongoDB

Factomize Core Dev Update 1 — Factomize

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nabil Makarim

Nabil Makarim

NIM (K3521056), EMAIL : bluerejet1330@gmail.com, UNIVERSITAS SEBELAS MARET

More from Medium

DATATYPES IN PYTHON-

Quick Python Console

Pythonic solution of the 2x2 Rubic cube

Rock Paper Scissors in Python