import sys dir(sys) #를 심심해서 했는데 stderr를 발견. sys.stderr = open('error.txt', 'w') #이 다음부터 발생한 error는 콘솔에 출력되지 않고 파일로 기록됨 #stderr, stdout, stdin 등등도 가능.
open("result.txt","w").write(open("source.txt").readline()[::-1])
#skywave import sys #set size if len(sys.argv) == 1: ySize = 3 xSize = 3 elif len(sys.argv) == 3: ySize, xSize = [int(x) for x in sys.argv[1:]] else: print("wrong argument number(s) (arg(s) with 0 or 2 length is allowed)") exit() if min(xSize, ySize) < 1: print("wrong list size - size should be positive") exit() totalSize = ySize * xSize #get input userInput = [int(x) for x in input("type {0} numbers:".format(totalSize)).split()] if len(userInput) != totalSize: print("wrong number of items ({0} instead of {1})".format(len(userInput), totalSize)) exit() #find max intList = [] for i in range(int(len(userInput) / xSize)): intList.append(userInput[i * xSize:(i + 1) * xSize]) intList[-1].append(max(intList[-1])) intList.append([]) for i in range(xSize + 1): intList[-1].append(max([x[i] for x in intList[:-1]])) #print print(intList)
f1 = open('source.txt','r') f2 = open('result.txt','w') string = f1.read() size = len(string) nstring = string[size::-1] f2.write(nstring) f1.close() f2.close()
nums1 = [0,0,0,0] nums2 = [0,0,0,0] nums3 = [0,0,0,0] for i in range(0,3) : number = input() nums1[i] = int(number) for i in range(0,3) : number = input() nums2[i] = int(number) for i in range(0,3) : number = input() nums3[i] = int(number) for i in range(0,3) : bignum = nums1[0] if nums1[i]>bignum: bignum = nums1[i] nums1[3] = bignum for i in range(0,3) : bignum = nums2[0] if nums2[i]>bignum : bignum = nums2[i] nums2[3] = bignum for i in range(0,3) : bignum = nums3[0] if nums3[i]>bignum : bignum = nums3[i] nums3[3] = bignum square = [nums1,nums2,nums3,[0,0,0,0]] for i in range(0,4) : bignum = square[0][i] for j in range(0,4) : if square[j][i]>bignum : bignum = square[j][i] square[3][i] = bignum for i in range(0,4) : for j in range(0,4) : bignum = square[0][0] if square[i][j]>bignum : bignum = square[i][j] square[3][3] = bignum for i in range(0,4) : print(square[i][0],square[i][1],square[i][2],square[i][3])
source = open('source.txt', 'r') result = open('result.txt', 'w') for line in source: result.write(line[::-1]) source.close() result.close()
size = 3 result = [] for i in range(0, size): tempList = [] for j in range(0, size): tempList.append(input("result: ")) tempList.append(max(tempList)) result.append(tempList) lastList = [] for i in range(0, size): tempList = [] for j in range(0, size): tempList.append(result[j][i]) lastList.append(max(tempList)) lastList.append(max(lastList)) result.append(lastList) print(result)
matrix = [] for i in range(3): row_max = 0 row = [] for j in input().split(" "): inputed_number = int(j) row.append(inputed_number) row.append(max(row)) matrix.append(row) row = [] for i in range(4): row.append(max(matrix[j][i] for j in range(3))) row[-1] = max(row) matrix.append(row) for row in matrix: print(row)
symbol_1 = ['I', 'X', 'C', 'M'] symbol_5 = ['V', 'L', 'D'] while True: try: user_input = int(input('Input a number (1 ~ 998, 999 to exit)')) except Exception: print('not valid input') continue if user_input == 999: print('good bye') exit() if user_input < 1 or user_input > 998: print('not valid input (must be 1 ~ 998)') continue stack = [] digit = 0 while user_input > 0: current_number = user_input % 10 current_string = '' user_input = int(user_input / 10) if current_number % 5 == 4: current_string += symbol_1[digit] if current_number == 4: current_string += symbol_5[digit] else: current_string += symbol_1[digit + 1] else: if current_number > 4: current_number -= 5 current_string += symbol_5[digit] current_string += symbol_1[digit] * current_number stack.append(current_string) digit += 1 while stack: print(stack.pop(), end='') print()
while True: try: user_input = int(input('Input a number (input < 1 to exit)')) except Exception: print('not valid input') continue if user_input < 1: print('good bye') exit() user_input -= 1 result = ['0', '1'] while user_input > 0: length = len(result) result *= 2 for i in range(length): result[i] = '0' + result[i] result[i + length] = '1' + result[i + length] user_input -= 1 print(result)
source = open('source.txt','r') result = open('result.txt','w') for line in source: romanNum='' isEmpty = line if isEmpty=='':break temp=int(isEmpty) if temp<=0: print('Too Small!') elif temp>999: print('Too Big!') elif temp==999: exit() else: while temp>=500: temp-=500 romanNum+='D' while temp>=100: temp-=100 romanNum+='C' while temp>=50: temp-=50 romanNum+='L' while temp>=10: temp-=10 romanNum+='X' if temp==1: romanNum+='I' elif temp==2: romanNum+='II' elif temp==3: romanNum+='III' elif temp==4: romanNum+='IV' elif temp==5: romanNum+='V' elif temp==6: romanNum+='VI' elif temp==7: romanNum+='VII' elif temp==8: romanNum+='VIII' elif temp==9: romanNum+='IX' romanNum+='\n' result.write(romanNum) source.close() result.close()
import random def cowsnbulls(answer_length): if type(answer_length) != int: print('answer_length must be a number') return if not 1 <= answer_length <= 10: print('answer_length must be between 1 and 10') return answer = [] numbers = list(range(10)) playing = True while len(answer) < answer_length: answer.append(numbers.pop(random.randrange(len(numbers)))) print(answer) print('Welcome to the Cows Bulls Game!') print('Enter a number:') while playing: try: user_input = [int(x) for x in list(input('>>> '))] except Exception: print('try again') continue if len(user_input) != answer_length: print('try again') continue if len([True for x in user_input for y in user_input if x == y]) != answer_length: print('try again') continue cows = len([True for x, y in zip(user_input, answer) if x == y]) bulls = len([True for x, y in enumerate(user_input) for z, w in enumerate(answer) if y == w and x != z]) print('{0} cow{1}, {2} bull{3}'.format(cows, 's' if cows > 1 else '', bulls, 's' if bulls > 1 else '')) if bulls == answer_length: playing = False if __name__ == '__main__': cowsnbulls(4)
import random answer = random.sample(range(10),4) while True: guess = [] error = 0 cow = 0 bull = 0 nums = input("Enter a number ") for x in nums: guess.append(int(x)) if len(guess) != 4: print("Wrong lenth") continue for n in range(0,4): for m in range(n+1,4): if guess[n] == guess[m]: error += 1 if error > 0: print("Wrong number") continue for x in range(0,4): if answer[x] == guess[x]: cow += 1 for n in range(0,4): for m in range(0,4): if n==m: continue if guess[n] == answer[m]: bull += 1 if cow>1: print(cow,'cows'+' ') else: print(cow,'cow'+' ') if bull>1: print(bull,'bulls'+' ') else: print(bull,'bull'+' ') if cow == 4: print('Win') break
import random print("Welcome to the Cows and Bulls Game!") answer = random.sample(range(10), 4) while(True): try: input_list = list(map(int, list(input("Enter a number : ")))) except ValueError: continue finally: pass if len(input_list) != 4: continue cow = 0 bull = 0 if answer == input_list: print("good, kids.") break else: for i in range(4): if input_list[i] == answer[i]: cow+=1 elif input_list[i] in answer: bull+=1 print("your input : ", input_list) print("cow : ", cow, " bull : ", bull) print(answer)