TIME NOW
World current time now,
CALENDAR
Calendar monthly, yearly
login CONVERT LENGTH
login CONVERT TEMPERATURE
login DICTIONARIES, LISTS
login SCIENCE EDUCATION RELIGION
login WORK CALCULATOR
login CALCULATE LIFE

Python 3 programming language, learn python, tutorial

Previous articlePage bottomNext article  ALL TOPICS

Python 3. if condition, statement

 py = 10, po = 20
  • ==      (py == po) is not true.
  • !=       (py != po) is  true.
  • <>      (py <> po) is true.
  • >        (py > po) is not true.
  • <        (py < po) is true.
  • >=      (py >= po) is not true.
  • <=      (py <= po) is true.
1. Simpliest condition:
x=10
if x < 0:
    x=1
    print (x)
 
x = 10

if x < 0:
    x=1
print (x)

1a. if condition example:
x = int(input("Please enter a number: "))

if x < 0:
    x = 0
    print('Data < 0')
elif x == 0:
    print('Data = 0 ')
elif x == 1:
    print('Data = 1 ')
else:
    print('Data > 0')

2. Indentation:
if True:
    print ("Yes")
else:
  print ("No")
 
3. Indentation:
if True:
    print ("Answer")
    print ("True")
else:
    print ("Answer")
  print ("False")

Result:
C:\Python34>python hello.py
  File "hello.py", line 6
    print ("False")
                  ^
IndentationError: unindent does not match any outer indentation level

4. Condition in the one row:
var = 100
if ( var  == 100 ) : print ("Value of expression is 100")


Previous articlePage topNext article  ALL TOPICS


Andrius:
1. 
x = int(input("Iveskite norima x reiksme: "))
y = int(input("Iveskite norima y reiksme: "))
if x > y:
print("Didesnis x - %d" % x)
elif x == y:
print("x ir y yra lygus")
else:
print("Didesnis y - %d" % y)

2. 
x = int(input("Iveskite norima x reiksme: "))
y = int(input("Iveskite norima y reiksme: "))
c = int
c = x + y
if c == 10:
print("Atsakymas lygus 10")
print(c)
elif c > 10:
print("Atsakymas didesnis uz 10")
print(c)
else:
print("Atsakymas mazesnis uz 10")
print(c)


2015-10-28 06:32:46
Vitalij:
x = int(input("Atspek skaiciu. Jusu skaicius: "))
if x<0 or x>10:
print("Iveskite skaiciu nuo 0 iki 10")
elif x==5:
print("atspejote skaiciu")
else: print("neatspejote skaiciu")



a,b,c =input("Iveskite 3 skaicius: ").split()
if a>b:
if a>c: print("didziausias ivestas skaicius: ",a)
else: print("didziausias ivestas skaicius: ",c)
else:
if b>c:print("didziausias ivestas skaicius: ",b)
else: print("didziausias ivestas skaicius: ",c)


2015-10-28 09:09:18
Mindaugas:
print ("=================pirmas pavyzdys=================")
var = 100
if var == 200:
   print ("1 - Got a true expression value")
   print (var)
elif var == 150:
   print ("2 - Got a true expression value")
   print (var)
elif var == 100:
   print ("3 - Got a true expression value")
   print (var)
else:
   print ("4 - Got a false expression value")
   print (var)

print ("Good bye!")
print("==================antras pavysdys=================")
people = int(input("Enter people count: "))
cars = int(input("Enter cars count: "))
trucks = int(input("Enter trucks count: "))


if cars > people:
    print ("We should take the cars.")
elif cars < people:
    print ("We should not take the cars.")
else:
    print ("We can't decide.")

if trucks > cars:
    print ("That's too many trucks.")
elif trucks < cars:
    print ("Maybe we could take the trucks.")
else:
    print ("We still can't decide.")

if people > trucks:
    print ("Alright, let's just take the trucks.")
else:
    print ("Fine, let's stay home then.")


print("=============trecias pavyzdys====================")

person = input("Nationality? ")
if person == "french" or person == "French" :
    print("Préférez-vous parler franēais?")
elif person == "italian" or person == "Italian":
    print("Preferisci parlare italiano?")
else:
    print("You are neither Italian nor French,")
    print("so we have to speak English with each other.")


2016-04-19 12:09:01
Paulius:
#!/usr/bin/python # # Python program to generate a random number with commentary. #   # Import is much like Java's.  This gets the random number generator. import random   # Generate a random integer in the range 10 to 49. i = random.randrange(10,50) print 'Your number is', i   # Carefully analyze the number for important properties. if i < 20:     print "That is less than 20."     if i % 3 == 0:         print "It is divisible by 3." elif i == 20:     print "That is exactly twenty.  How nice for you." else:     if i % 2 == 1:         print "That is an odd number."     else:         print "That is twice", i / 2, '.'     print "Wow! That's more than 20!"

2016-05-03 11:16:29

 Use username: Guest, Anonymous, Programmer






QUOTES:
I have found out that there ain't no surer way to find out whether you like people or hate them than to travel with them.
Mark Twain
I care not so much what I am in the opinion of others, as what I am in my own; I would be rich of myself and not by borrowing.
Michel Eyquem De Montaigne
Only in dreams does the happiness of the earth dwell.
Ruckett