Уведомления

Группа в Telegram: @pythonsu

#1 Фев. 3, 2015 00:18:43

Kon52
Зарегистрирован: 2015-01-31
Сообщения: 66
Репутация: +  3  -
Профиль   Отправить e-mail  

Что не так?

Здравствуйте, начал изучать 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- не верно……
странно как- то, подскажите, кто- нибудь.

Офлайн

#2 Фев. 3, 2015 00:34:33

terabayt
От: Киев
Зарегистрирован: 2011-11-26
Сообщения: 1099
Репутация: +  103  -
Профиль   Отправить e-mail  

Что не так?

эмм… :/
возле смайликов наведите слева на лист и выберите Python
и вот туда вставляйте этот код
мне даже страшно представить что там…
изображение



————————————————
-*- Simple is better than complex -*-

Отредактировано terabayt (Фев. 3, 2015 00:40:03)

Офлайн

#3 Фев. 3, 2015 06:38:32

Kon52
Зарегистрирован: 2015-01-31
Сообщения: 66
Репутация: +  3  -
Профиль   Отправить e-mail  

Что не так?

#!/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()

Офлайн

#4 Фев. 3, 2015 08:09:18

py.user.next
От:
Зарегистрирован: 2010-04-29
Сообщения: 10015
Репутация: +  857  -
Профиль   Отправить e-mail  

Что не так?

И ведь не сломался интерпретатор, выдержал. :D



Офлайн

#5 Фев. 3, 2015 11:06:25

terabayt
От: Киев
Зарегистрирован: 2011-11-26
Сообщения: 1099
Репутация: +  103  -
Профиль   Отправить e-mail  

Что не так?

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')



————————————————
-*- Simple is better than complex -*-

Офлайн

#6 Фев. 3, 2015 13:37:43

alex925
Зарегистрирован: 2015-01-08
Сообщения: 204
Репутация: +  14  -
Профиль   Отправить e-mail  

Что не так?

После увиденного, я спать не смогу O_0

Отредактировано alex925 (Фев. 3, 2015 14:47:47)

Офлайн

#7 Фев. 3, 2015 14:34:47

Kon52
Зарегистрирован: 2015-01-31
Сообщения: 66
Репутация: +  3  -
Профиль   Отправить e-mail  

Что не так?

terabayt
Только не это
Я прекрасно понимаю, что язык содержит кучу прекрасных функций и операторов, но я до них еще не дошел.
У меня опыта 2 дня, и вопрос был в другом.

P. s. Кстати, почему не
m = max(a,b,c)
print m
raw_input('press enter to exit') ?

Офлайн

#8 Фев. 3, 2015 14:41:01

Kon52
Зарегистрирован: 2015-01-31
Сообщения: 66
Репутация: +  3  -
Профиль   Отправить e-mail  

Что не так?


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

Офлайн

#9 Фев. 3, 2015 14:44:56

alex925
Зарегистрирован: 2015-01-08
Сообщения: 204
Репутация: +  14  -
Профиль   Отправить e-mail  

Что не так?

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)

Офлайн

#10 Фев. 3, 2015 16:06:27

4kpt_III
Зарегистрирован: 2014-12-22
Сообщения: 999
Репутация: +  39  -
Профиль   Отправить e-mail  

Что не так?

alex925
А я такое уже видел. И не раз и не два Поэтому у меня выработался иммунитет…

Kon52
По-вашему вопросу. Не пишите сложных вещей (это реально жутко), пока не изучили хотя-бы основы: логика, циклы, функции. Плюс желательно почитать о внутренних функциях и возможностях питона.

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version