Форум сайта python.su
3
Здравствуйте, начал изучать Python, изучил как работает инструкция if-else, решил написать маленькую программку для вычисления наибольшего из 3х чисел, дабы попрактиковаться.
Код:
#!/usr/bin/env python
#coding=utf-8
a=raw_input('a=')
b=raw_input('b=')
c=raw_input('c=')
if a<=b<c:
print c
raw_input('press enter to exit')
exit()
else:
if b<=a<c:
print c
raw_input('press enter to exit')
exit()
else:
if a<b<=c:
print c
print b
raw_input('press enter to exit')
exit()
else:
if b<=a<=c:
if a==b==c:
print c
print b
print c
raw_input('press enter to exit')
exit()
else:
if b<a<=c:
print a
print c
raw_input('press enter to exit')
exit()
else:
if c<=b<a:
print a
raw_input('press enter to exit')
exit()
else:
if b<=c<a:
print a
raw_input('press enter to exit')
exit()
else:
if c<b<=a:
print a
print b
raw_input('press enter to exit')
exit()
else:
if b<=c<=a:
if a==b==c:
print c
print b
print c
raw_input('press enter to exit')
exit()
else:
if b<c<=a:
print a
print c
raw_input('press enter to exit')
exit()
else:
if a<=c<b:
print b
raw_input('press enter to exit')
exit()
else:
if c<=a<b:
print b
raw_input('press enter to exit')
exit()
else:
if a<c<=b:
print c
print b
raw_input('press enter to exit')
exit()
else:
if c<=a<=b:
if a==b==c:
print c
print b
print c
raw_input('press enter to exit')
exit()
else:
c<a<=b
print a
print b
raw_input('press enter to exit')
exit()
else:
c<a<=b
print a
print b
raw_input('press enter to exit')
exit()
else:
if b<c<=a:
print a
print c
raw_input('press enter to exit')
exit()
else:
if a<=c<b:
print b
raw_input('press enter to exit')
exit()
else:
if c<=a<b:
print b
raw_input('press enter to exit')
exit()
else:
if a<c<=b:
print c
print b
raw_input('press enter to exit')
exit()
else:
if c<=a<=b:
if a==b==c:
print c
print b
print c
raw_input('press enter to exit')
exit()
else:
c<a<=b
print a
print b
raw_input('press enter to exit')
exit()
else:
c<a<=b
print a
print b
raw_input('press enter to exit')
exit()
else:
if b<a<=c:
print a
print c
raw_input('press enter to exit')
exit()
else:
if c<=b<a:
print a
raw_input('press enter to exit')
exit()
else:
if b<=c<a:
print a
raw_input('press enter to exit')
exit()
else:
if c<b<=a:
print a
print b
raw_input('press enter to exit')
exit()
else:
if b<=c<=a:
if a==b==c:
print c
print b
print c
raw_input('press enter to exit')
exit()
else:
if b<c<=a:
print a
print c
raw_input('press enter to exit')
exit()
else:
if a<=c<b:
print b
raw_input('press enter to exit')
exit()
else:
if c<=a<b:
print b
raw_input('press enter to exit')
exit()
else:
if a<c<=b:
print c
print b
raw_input('press enter to exit')
exit()
else:
if c<=a<=b:
if a==b==c:
print c
print b
print c
raw_input('press enter to exit')
exit()
else:
c<a<=b
print a
print b
raw_input('press enter to exit')
exit()
else:
c<a<=b
print a
print b
raw_input('press enter to exit')
exit()
else:
if b<c<=a:
print a
print c
raw_input('press enter to exit')
exit()
else:
if a<=c<b:
print b
raw_input('press enter to exit')
exit()
else:
if c<=a<b:
print b
raw_input('press enter to exit')
exit()
else:
if a<c<=b:
print c
print b
raw_input('press enter to exit')
exit()
else:
if c<=a<=b:
if a==b==c:
print c
print b
print c
raw_input('press enter to exit')
exit()
else:
c<a<=b
print a
print b
raw_input('press enter to exit')
exit()
else:
c<a<=b
print a
print b
raw_input('press enter to exit')
exit()
Всё работает, но результат не всегда верно выдает..
Например:
a=1
b=2
c=3
3- все верно.
a=3
b=2
c=1
3- опять ОК.
НО:
a=324
b=9776
c=534343
9776- не верно……
странно как- то, подскажите, кто- нибудь.
Офлайн
103
эмм… :/
возле смайликов наведите слева на лист и выберите Python
и вот туда вставляйте этот код
мне даже страшно представить что там…
изображение
Отредактировано terabayt (Фев. 3, 2015 00:40:03)
Офлайн
3
#!/usr/bin/env python #coding=utf-8 a=raw_input('a=') b=raw_input('b=') c=raw_input('c=') if a<=b<c: print c raw_input('press enter to exit') exit() else: if b<=a<c: print c raw_input('press enter to exit') exit() else: if a<b<=c: print c print b raw_input('press enter to exit') exit() else: if b<=a<=c: if a==b==c: print c print b print c raw_input('press enter to exit') exit() else: if b<a<=c: print a print c raw_input('press enter to exit') exit() else: if c<=b<a: print a raw_input('press enter to exit') exit() else: if b<=c<a: print a raw_input('press enter to exit') exit() else: if c<b<=a: print a print b raw_input('press enter to exit') exit() else: if b<=c<=a: if a==b==c: print c print b print c raw_input('press enter to exit') exit() else: if b<c<=a: print a print c raw_input('press enter to exit') exit() else: if a<=c<b: print b raw_input('press enter to exit') exit() else: if c<=a<b: print b raw_input('press enter to exit') exit() else: if a<c<=b: print c print b raw_input('press enter to exit') exit() else: if c<=a<=b: if a==b==c: print c print b print c raw_input('press enter to exit') exit() else: c<a<=b print a print b raw_input('press enter to exit') exit() else: c<a<=b print a print b raw_input('press enter to exit') exit() else: if b<c<=a: print a print c raw_input('press enter to exit') exit() else: if a<=c<b: print b raw_input('press enter to exit') exit() else: if c<=a<b: print b raw_input('press enter to exit') exit() else: if a<c<=b: print c print b raw_input('press enter to exit') exit() else: if c<=a<=b: if a==b==c: print c print b print c raw_input('press enter to exit') exit() else: c<a<=b print a print b raw_input('press enter to exit') exit() else: c<a<=b print a print b raw_input('press enter to exit') exit() else: if b<a<=c: print a print c raw_input('press enter to exit') exit() else: if c<=b<a: print a raw_input('press enter to exit') exit() else: if b<=c<a: print a raw_input('press enter to exit') exit() else: if c<b<=a: print a print b raw_input('press enter to exit') exit() else: if b<=c<=a: if a==b==c: print c print b print c raw_input('press enter to exit') exit() else: if b<c<=a: print a print c raw_input('press enter to exit') exit() else: if a<=c<b: print b raw_input('press enter to exit') exit() else: if c<=a<b: print b raw_input('press enter to exit') exit() else: if a<c<=b: print c print b raw_input('press enter to exit') exit() else: if c<=a<=b: if a==b==c: print c print b print c raw_input('press enter to exit') exit() else: c<a<=b print a print b raw_input('press enter to exit') exit() else: c<a<=b print a print b raw_input('press enter to exit') exit() else: if b<c<=a: print a print c raw_input('press enter to exit') exit() else: if a<=c<b: print b raw_input('press enter to exit') exit() else: if c<=a<b: print b raw_input('press enter to exit') exit() else: if a<c<=b: print c print b raw_input('press enter to exit') exit() else: if c<=a<=b: if a==b==c: print c print b print c raw_input('press enter to exit') exit() else: c<a<=b print a print b raw_input('press enter to exit') exit() else: c<a<=b print a print b raw_input('press enter to exit') exit()
Офлайн
857
И ведь не сломался интерпретатор, выдержал. :D
Офлайн
103
a=input('a=') b=input('b=') c=input('c=') m = max(a,b,c) print ('%s\n' % m) * (a,b,c).count(m) raw_input('press enter to exit')
Офлайн
14
После увиденного, я спать не смогу O_0
Отредактировано alex925 (Фев. 3, 2015 14:47:47)
Офлайн
3
terabaytТолько не это

Офлайн
3
alex925Как и я после слов “уведенного” и нарушений правил пунктуации, так что в какой- то мере я тебя понимаю.
После уведенного, я спать не смогу O_0

Офлайн
14
Kon52
Если даже ты не хочешь использовать функцию max, то задача решается куда более просто.
P.S Чтобы не быть голословным:
data = (10, 38, 5) max_num = data[0] for index in range(len(data)): if max_num < data[index]: max_num = data[index] print(max_num)
Отредактировано alex925 (Фев. 3, 2015 16:36:31)
Офлайн
39
alex925
А я такое уже видел. И не раз и не два
Поэтому у меня выработался иммунитет…
Kon52
По-вашему вопросу. Не пишите сложных вещей (это реально жутко), пока не изучили хотя-бы основы: логика, циклы, функции. Плюс желательно почитать о внутренних функциях и возможностях питона.
Офлайн