├── Assignment15 ├── README.md └── bot.py ├── Assignment14 ├── T-rex runner │ ├── db │ │ └── high_score.txt │ ├── images │ │ ├── dino.png │ │ ├── down0.png │ │ ├── down1.png │ │ ├── moon.png │ │ ├── star.png │ │ ├── walk0.png │ │ ├── walk1.png │ │ ├── ground0.png │ │ ├── ground1.png │ │ ├── ground2.png │ │ ├── ground3.png │ │ ├── ground4.png │ │ ├── cloud_night.png │ │ ├── pterodactyl0.png │ │ ├── pterodactyl1.png │ │ ├── background_day.png │ │ ├── cactus1_night.png │ │ ├── cactus4_night.png │ │ └── background_night.png │ ├── cactus.py │ ├── ground.py │ ├── pterodactyl.py │ ├── dino.py │ └── main.py └── README.md ├── Assignment06 └── store │ ├── database.txt │ ├── qrcode │ └── milkQR.png │ └── main.py ├── Assignment18 ├── Translator En-Fa │ ├── requirements.txt │ ├── translator.jpg │ ├── main.py │ └── translator.ui ├── sudoku │ ├── icon.png │ ├── data │ │ ├── s1.txt │ │ ├── s2.txt │ │ ├── s3.txt │ │ ├── s4.txt │ │ ├── s5.txt │ │ └── s6.txt │ ├── Sudoku.ui │ └── main.py ├── converter │ ├── icon.jpg │ ├── main.py │ └── unitConverter.ui ├── Guess the number │ ├── icon.png │ ├── main.py │ └── guessTheNumber.ui ├── Password generator │ ├── key.png │ ├── main.py │ └── passwordGenerator.ui └── README.md ├── Assignment04 ├── 4_wordcounter.py ├── 6_gcd.py ├── 1_chessBoard.py ├── 7_lcm.py ├── 5_factorialOrNot.py ├── 3_multiplicationTable.py └── 2_quadraticEquation.py ├── Assignment08 ├── pictures │ └── readme.txt ├── 2_gif.py ├── 3_diamond.py ├── 6_complexNumbers.py ├── 4_fraction.py ├── 1_rockPaperScissor.py └── 5_time.py ├── Assignment17 ├── xo.jpg ├── README.md └── main.py ├── Assignment21 ├── img │ ├── 1.jpg │ ├── 2.jpg │ ├── 3.jpg │ ├── 4.jpg │ └── polar_bear.jpg ├── 4_color_separation.py ├── 6_gradient.py ├── 2_color_correction.py ├── 5_corner_line.py ├── 3_rotate_image.py ├── 7_letter_B.py ├── 1_checkered_board.py └── README.md ├── Assignment19 ├── digikala.db ├── check_symmetric_list.py ├── pair_randomly.py ├── commands.sql └── Palam_Polom_Pilish.py ├── Assignment20 ├── to do │ ├── db.db │ ├── images │ │ ├── pin.png │ │ ├── detail.png │ │ ├── unpin.png │ │ ├── detail_icon.png │ │ └── todolisticon.png │ ├── database.py │ ├── todolist.ui │ ├── main.py │ └── popup.ui ├── AI Snake │ ├── img │ │ ├── pear.png │ │ ├── apple.png │ │ └── dynamite.png │ └── main.py ├── telegram bot │ ├── song.wav │ └── main.py └── README.md ├── Assignment02 ├── 2_timeToSec.py ├── 1_sum.py ├── 6_fibonacci.py ├── 3_secToTime.py ├── 4_studentMeanMaxMin.py └── 5_dice.py ├── Assignment12 ├── img │ └── heart.png ├── READme.md └── main.py ├── Assignment11 ├── snake │ ├── img │ │ ├── apple.png │ │ ├── pear.png │ │ ├── poop.png │ │ └── dynamite.png │ └── main.py └── complex loops │ └── main.py ├── Assignment13 └── platform │ ├── images │ └── snow.png │ ├── ground.py │ ├── enemy.py │ ├── player.py │ └── main.py ├── Assignment03 ├── 2_randomNumberInList.py ├── 3_sortedOrNot.py ├── 4_snake.py └── 1_simpleHangman.py ├── Assignment10-Mini Project ├── qrcode │ └── takedel.png ├── actor.py ├── film.py ├── clip.py ├── db.csv ├── documentary.py ├── series.py ├── media.py └── main.py ├── Assignment07 ├── videoToAudio │ └── main.py └── Translator │ ├── main.py │ └── translate.txt ├── Assignment01 ├── 2_triangleOrNot.py ├── 4_avgAndState.py ├── 3_bmi.py └── 1_calculator.py ├── Assignment16 ├── README.md └── main.py ├── Assignment05 ├── 1_khayamPaskalTriangle.py ├── 3_turtle.py └── 2_ticTocToe.py ├── LICENSE ├── Assignment09 ├── 1_fractionsUsingClass.py └── 2_timeUsingClass.py └── README.md /Assignment15/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Assignment14/T-rex runner/db/high_score.txt: -------------------------------------------------------------------------------- 1 | 43 -------------------------------------------------------------------------------- /Assignment06/store/database.txt: -------------------------------------------------------------------------------- 1 | 7890,banana,3000,8 2 | 8705,apple,8200,90 3 | -------------------------------------------------------------------------------- /Assignment18/Translator En-Fa/requirements.txt: -------------------------------------------------------------------------------- 1 | googletrans==4.0.0rc1 2 | PySide6 -------------------------------------------------------------------------------- /Assignment04/4_wordcounter.py: -------------------------------------------------------------------------------- 1 | sentence = list(input().split()) 2 | print(len(sentence)) 3 | -------------------------------------------------------------------------------- /Assignment08/pictures/readme.txt: -------------------------------------------------------------------------------- 1 | This dir is a place to keep pictures to making gif in 2nd exercise. 2 | -------------------------------------------------------------------------------- /Assignment17/xo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment17/xo.jpg -------------------------------------------------------------------------------- /Assignment21/img/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment21/img/1.jpg -------------------------------------------------------------------------------- /Assignment21/img/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment21/img/2.jpg -------------------------------------------------------------------------------- /Assignment21/img/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment21/img/3.jpg -------------------------------------------------------------------------------- /Assignment21/img/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment21/img/4.jpg -------------------------------------------------------------------------------- /Assignment19/digikala.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment19/digikala.db -------------------------------------------------------------------------------- /Assignment20/to do/db.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment20/to do/db.db -------------------------------------------------------------------------------- /Assignment02/2_timeToSec.py: -------------------------------------------------------------------------------- 1 | time=list(map(int, input().split(':'))) 2 | print(time[0]*3600 + time[1]*60 + time[2]) 3 | -------------------------------------------------------------------------------- /Assignment12/img/heart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment12/img/heart.png -------------------------------------------------------------------------------- /Assignment18/sudoku/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment18/sudoku/icon.png -------------------------------------------------------------------------------- /Assignment11/snake/img/apple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment11/snake/img/apple.png -------------------------------------------------------------------------------- /Assignment11/snake/img/pear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment11/snake/img/pear.png -------------------------------------------------------------------------------- /Assignment11/snake/img/poop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment11/snake/img/poop.png -------------------------------------------------------------------------------- /Assignment18/converter/icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment18/converter/icon.jpg -------------------------------------------------------------------------------- /Assignment21/img/polar_bear.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment21/img/polar_bear.jpg -------------------------------------------------------------------------------- /Assignment20/AI Snake/img/pear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment20/AI Snake/img/pear.png -------------------------------------------------------------------------------- /Assignment20/telegram bot/song.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment20/telegram bot/song.wav -------------------------------------------------------------------------------- /Assignment20/to do/images/pin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment20/to do/images/pin.png -------------------------------------------------------------------------------- /Assignment06/store/qrcode/milkQR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment06/store/qrcode/milkQR.png -------------------------------------------------------------------------------- /Assignment11/snake/img/dynamite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment11/snake/img/dynamite.png -------------------------------------------------------------------------------- /Assignment13/platform/images/snow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment13/platform/images/snow.png -------------------------------------------------------------------------------- /Assignment20/AI Snake/img/apple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment20/AI Snake/img/apple.png -------------------------------------------------------------------------------- /Assignment20/to do/images/detail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment20/to do/images/detail.png -------------------------------------------------------------------------------- /Assignment20/to do/images/unpin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment20/to do/images/unpin.png -------------------------------------------------------------------------------- /Assignment18/Guess the number/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment18/Guess the number/icon.png -------------------------------------------------------------------------------- /Assignment18/Password generator/key.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment18/Password generator/key.png -------------------------------------------------------------------------------- /Assignment20/AI Snake/img/dynamite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment20/AI Snake/img/dynamite.png -------------------------------------------------------------------------------- /Assignment03/2_randomNumberInList.py: -------------------------------------------------------------------------------- 1 | from random import sample 2 | n = int(input()) 3 | randomList=sample(range(0, n*5), n) 4 | print(randomList) 5 | -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/dino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/dino.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/down0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/down0.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/down1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/down1.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/moon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/moon.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/star.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/walk0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/walk0.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/walk1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/walk1.png -------------------------------------------------------------------------------- /Assignment20/to do/images/detail_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment20/to do/images/detail_icon.png -------------------------------------------------------------------------------- /Assignment20/to do/images/todolisticon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment20/to do/images/todolisticon.png -------------------------------------------------------------------------------- /Assignment02/1_sum.py: -------------------------------------------------------------------------------- 1 | sum=0 2 | while True: 3 | temp=input() 4 | if temp=='exit': 5 | break 6 | sum+=float(temp) 7 | print(sum) 8 | -------------------------------------------------------------------------------- /Assignment10-Mini Project/qrcode/takedel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment10-Mini Project/qrcode/takedel.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/ground0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/ground0.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/ground1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/ground1.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/ground2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/ground2.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/ground3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/ground3.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/ground4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/ground4.png -------------------------------------------------------------------------------- /Assignment18/Translator En-Fa/translator.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment18/Translator En-Fa/translator.jpg -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/cloud_night.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/cloud_night.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/pterodactyl0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/pterodactyl0.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/pterodactyl1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/pterodactyl1.png -------------------------------------------------------------------------------- /Assignment10-Mini Project/actor.py: -------------------------------------------------------------------------------- 1 | class Actor: 2 | def __init__(self, NAME): 3 | self.name = NAME 4 | def get_name(self): 5 | return self.name -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/background_day.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/background_day.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/cactus1_night.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/cactus1_night.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/cactus4_night.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/cactus4_night.png -------------------------------------------------------------------------------- /Assignment14/T-rex runner/images/background_night.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BenyaminZojaji/Python-Assignments/HEAD/Assignment14/T-rex runner/images/background_night.png -------------------------------------------------------------------------------- /Assignment03/3_sortedOrNot.py: -------------------------------------------------------------------------------- 1 | userInputList=list(map(int, input().split())) 2 | copyUserL=userInputList.copy() 3 | userInputList.sort() 4 | print('yes') if userInputList==copyUserL else print('no') 5 | -------------------------------------------------------------------------------- /Assignment07/videoToAudio/main.py: -------------------------------------------------------------------------------- 1 | from moviepy import editor 2 | video = editor.VideoFileClip('Mohsen Yeganeh - Behet Ghol Midam.mp4') 3 | video.audio.write_audiofile('Mohsen Yeganeh - Behet Ghol Midam.mp3') 4 | -------------------------------------------------------------------------------- /Assignment04/6_gcd.py: -------------------------------------------------------------------------------- 1 | def gcd(x, y): 2 | while y: 3 | x, y = y, x%y 4 | return x 5 | numbers = list(map(int, input('two numbers pls: e.g. 3 6\n').split())) 6 | print(gcd(numbers[0], numbers[1])) 7 | -------------------------------------------------------------------------------- /Assignment18/sudoku/data/s1.txt: -------------------------------------------------------------------------------- 1 | 3 8 0 6 4 0 9 0 7 2 | 5 0 0 1 0 3 0 2 8 3 | 1 4 7 2 0 0 3 0 6 4 | 7 5 0 0 2 0 6 4 0 5 | 8 0 0 7 1 4 0 0 5 6 | 0 2 1 5 9 6 8 7 0 7 | 2 3 0 4 6 7 0 0 9 8 | 0 0 4 0 0 1 5 0 2 9 | 6 1 8 9 0 0 0 3 4 -------------------------------------------------------------------------------- /Assignment18/sudoku/data/s2.txt: -------------------------------------------------------------------------------- 1 | 5 6 8 7 3 0 1 0 4 2 | 7 0 4 2 1 8 0 3 0 3 | 2 0 1 0 6 5 0 7 8 4 | 3 0 5 6 4 0 2 9 7 5 | 0 0 6 9 8 2 4 5 3 6 | 9 0 0 0 0 7 0 8 1 7 | 4 0 9 8 7 0 0 1 2 8 | 6 2 0 0 9 0 0 0 0 9 | 0 1 3 0 0 4 0 0 9 -------------------------------------------------------------------------------- /Assignment18/sudoku/data/s3.txt: -------------------------------------------------------------------------------- 1 | 5 4 0 3 6 2 0 9 7 2 | 3 1 0 0 5 7 6 8 0 3 | 0 6 7 1 9 8 0 5 0 4 | 8 2 4 0 0 1 0 0 6 5 | 0 5 0 6 2 0 8 1 0 6 | 1 9 0 8 3 5 0 0 4 7 | 9 0 1 2 4 6 0 7 0 8 | 4 0 5 0 8 0 0 6 0 9 | 0 7 0 5 0 3 9 0 8 -------------------------------------------------------------------------------- /Assignment18/sudoku/data/s4.txt: -------------------------------------------------------------------------------- 1 | 0 9 5 0 2 3 0 4 0 2 | 0 7 0 8 9 6 0 3 0 3 | 8 0 2 0 4 0 9 7 6 4 | 7 5 0 6 3 8 0 9 0 5 | 3 2 0 9 0 4 6 5 1 6 | 0 0 9 1 5 0 3 8 7 7 | 0 1 6 4 0 0 7 2 3 8 | 0 4 0 3 1 5 0 0 0 9 | 0 0 0 2 6 7 4 1 0 -------------------------------------------------------------------------------- /Assignment18/sudoku/data/s5.txt: -------------------------------------------------------------------------------- 1 | 0 0 0 0 0 0 0 0 0 2 | 1 0 0 0 0 0 0 0 0 3 | 0 0 0 0 0 0 0 0 0 4 | 0 0 0 0 0 0 0 0 0 5 | 0 0 0 0 0 0 0 0 0 6 | 0 0 0 0 0 0 0 0 0 7 | 0 0 0 0 0 0 0 0 0 8 | 2 0 0 0 0 0 0 0 0 9 | 0 0 0 0 0 0 0 0 0 -------------------------------------------------------------------------------- /Assignment18/sudoku/data/s6.txt: -------------------------------------------------------------------------------- 1 | 8 0 0 0 0 0 0 0 0 2 | 0 0 3 6 0 0 0 0 0 3 | 0 7 0 0 9 0 2 0 0 4 | 0 5 0 0 0 7 0 0 0 5 | 0 0 0 0 4 5 7 0 0 6 | 0 0 0 1 0 0 0 3 0 7 | 0 0 1 0 0 0 0 6 8 8 | 0 0 8 5 0 0 0 1 0 9 | 0 9 0 0 0 0 4 0 0 -------------------------------------------------------------------------------- /Assignment03/4_snake.py: -------------------------------------------------------------------------------- 1 | def snakeAssembler(n): 2 | while n!=0: 3 | yield '*' 4 | n-=1 5 | if n==0:break 6 | yield '#' 7 | n-=1 8 | print(''.join(list(snakeAssembler(int(input()))))) 9 | -------------------------------------------------------------------------------- /Assignment08/2_gif.py: -------------------------------------------------------------------------------- 1 | from os import listdir 2 | from imageio import imread, mimsave 3 | myPics=listdir('pictures') 4 | images=[] 5 | for name in myPics: 6 | images.append(imread('pictures/'+name)) 7 | mimsave('penSpinner.gif', images) 8 | -------------------------------------------------------------------------------- /Assignment04/1_chessBoard.py: -------------------------------------------------------------------------------- 1 | n, m = map(int, input().split()) 2 | for i in range(n): 3 | for j in range(m): 4 | if (i+j)%2==0: 5 | print('#', end='') 6 | else: 7 | print('*', end='') 8 | print('\n') 9 | -------------------------------------------------------------------------------- /Assignment02/6_fibonacci.py: -------------------------------------------------------------------------------- 1 | n=int(input()) 2 | fiboList=[] 3 | for i in range(n): 4 | if i < 2: 5 | fiboList.append(1) 6 | else: 7 | fiboList.append(fiboList[i-1]+fiboList[i-2]) 8 | print(','.join(list(map(str, fiboList)))) 9 | -------------------------------------------------------------------------------- /Assignment01/2_triangleOrNot.py: -------------------------------------------------------------------------------- 1 | a, b, c=map(int, input('give me three sides: ').split()) 2 | if a9 else '0'+str(x),timeList)) 7 | print(':'.join(timeList)) 8 | -------------------------------------------------------------------------------- /Assignment02/4_studentMeanMaxMin.py: -------------------------------------------------------------------------------- 1 | from statistics import mean 2 | scoreList=[] 3 | n=int(input()) 4 | for i in range(n): 5 | scoreList.append(float(input())) 6 | scoreList.sort() 7 | print('Mean: %f ,Max: %f ,Min: %f' %(mean(scoreList), scoreList.pop(), scoreList[0])) 8 | -------------------------------------------------------------------------------- /Assignment19/check_symmetric_list.py: -------------------------------------------------------------------------------- 1 | arr = list(map(int, input().split())) 2 | flag=True 3 | for i in range(len(arr)): 4 | if arr[i]!=arr[len(arr)-1-i]: 5 | flag=False 6 | break 7 | if flag: 8 | print('symmetric') 9 | else: 10 | print('not symmetric') -------------------------------------------------------------------------------- /Assignment19/pair_randomly.py: -------------------------------------------------------------------------------- 1 | from random import shuffle 2 | 3 | boys = ['ali', 'reza', 'yasin', 'benyamin', 'mehrdad', 'sajjad', 'aidin', 'shahin'] 4 | girls = ['sara', 'zari', 'neda', 'homa', 'eli', 'goli', 'mary', 'mina'] 5 | shuffle(girls) 6 | print(f'result = {list(zip(boys, girls))}') -------------------------------------------------------------------------------- /Assignment01/4_avgAndState.py: -------------------------------------------------------------------------------- 1 | from math import mean 2 | name, family=input().split() 3 | g1, g2, g3 = input().split() 4 | avg = mean(float(g1), float(g2), float(g3)) 5 | if avg<12: 6 | print('Fail') 7 | elif avg<17: 8 | print('Normal') 9 | else: 10 | print('Great') 11 | -------------------------------------------------------------------------------- /Assignment21/4_color_separation.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | img = cv2.imread('img/4.jpg', 0) 4 | height, width = img.shape 5 | 6 | for i in range(height): 7 | for j in range(width): 8 | if img[i][j]<110: 9 | img[i][j] = 0 10 | 11 | cv2.imwrite('result_4.png', img) -------------------------------------------------------------------------------- /Assignment21/6_gradient.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img_arr = np.arange(0, 65025, 1, np.uint8) 5 | img = np.reshape(img_arr, (255, 255)) 6 | height, width = img.shape 7 | 8 | for i in range(height): 9 | img[i, :]=height-i 10 | 11 | cv2.imwrite('result_6.png', img) -------------------------------------------------------------------------------- /Assignment21/2_color_correction.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | img1 = cv2.imread('img/1.jpg') 4 | img2 = cv2.imread('img/2.jpg') 5 | 6 | inverted_img1 = cv2.bitwise_not(img1) 7 | inverted_img2 = cv2.bitwise_not(img2) 8 | 9 | cv2.imwrite('result_2_1.png', inverted_img1) 10 | cv2.imwrite('result_2_2.png', inverted_img2) -------------------------------------------------------------------------------- /Assignment21/5_corner_line.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | img = cv2.imread('img/polar_bear.jpg', 1) 4 | 5 | height, width, _ = img.shape 6 | 7 | for j in range(400): #height 8 | for k in range(85): #width 9 | if not 300-j+k<0: 10 | img[j][300-j+k]= 0 11 | 12 | cv2.imwrite('result_5.png', img) -------------------------------------------------------------------------------- /Assignment16/README.md: -------------------------------------------------------------------------------- 1 | ## Calculator 2 | - Simple GUI calculator in **Python** using **PySide6** 3 | - feautures: 4 | - [x] + - * / 5 | - [x] sin, cos, tan, cot 6 | - [x] log, sqrt 7 | - view: 8 | - ![calculator view](https://user-images.githubusercontent.com/77120507/135714897-cba6ec69-a3e1-4105-aee2-5ee9d70dc8c9.png) 9 | -------------------------------------------------------------------------------- /Assignment17/README.md: -------------------------------------------------------------------------------- 1 | ## Tik Tok Toe 2 | - Tik Tok Toe game written in **Python** using PySide6. 3 | - features: 4 | - [x] Single player(with AI) and two player 5 | - [x] Scoreboard 6 | - [x] About button 7 | - view: 8 | - ![TikTokToe](https://user-images.githubusercontent.com/77120507/136216879-d66e160e-823f-4f67-b4e4-93a4ba6faacc.png) 9 | -------------------------------------------------------------------------------- /Assignment13/platform/ground.py: -------------------------------------------------------------------------------- 1 | import arcade 2 | class Ground(arcade.Sprite): 3 | def __init__(self , x, y): 4 | super().__init__() 5 | self.texture = arcade.load_texture(":resources:images/tiles/grassHalf_mid.png") 6 | self.center_x = x 7 | self.center_y = y 8 | self.width = 115 9 | self.height = 115 -------------------------------------------------------------------------------- /Assignment04/5_factorialOrNot.py: -------------------------------------------------------------------------------- 1 | def isFactorialFunc(n): 2 | total = 1 3 | i=1 4 | while total<=n: 5 | total*=i 6 | i+=1 7 | if total==n: 8 | return True 9 | return False 10 | number = int(input()) 11 | if isFactorialFunc(number): 12 | print('Yes') 13 | else: 14 | print('No') 15 | -------------------------------------------------------------------------------- /Assignment01/3_bmi.py: -------------------------------------------------------------------------------- 1 | weight=float(input('weight(kg): ')) 2 | height=float(input('height(meter): ')) 3 | bmi=weight/height**2 4 | if bmi<18.5: 5 | print('under weight') 6 | elif bmi<25: 7 | print('normal') 8 | elif bmi<30: 9 | print('over weight') 10 | elif bmi<35: 11 | print('obese') 12 | else: 13 | print('extremly obese') 14 | -------------------------------------------------------------------------------- /Assignment21/3_rotate_image.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img = cv2.imread('img/3.jpg', 0) 5 | height, width = img.shape 6 | 7 | arr = np.arange(0, height*width, 1, np.uint8) 8 | rev_img = np.reshape(arr, (height, width)) 9 | 10 | for i in range(height): 11 | for j in range(width): 12 | rev_img[height-i-1][width-j-1] = img[i][j] 13 | 14 | 15 | cv2.imwrite('result_3.png', rev_img) -------------------------------------------------------------------------------- /Assignment21/7_letter_B.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img_arr = np.arange(0, 90000, 1, np.uint8) 5 | img = np.reshape(img_arr, (300, 300)) 6 | height, width = img.shape 7 | 8 | img[:,:]=255 9 | img[50:250, 50:100]=0 10 | 11 | img[50:90, 100:160]=0 12 | img[210:250, 100:160]=0 13 | img[130:170, 100:160]=0 14 | 15 | img[70:140, 160:210]=0 16 | img[160:230, 160:210]=0 17 | 18 | cv2.imwrite('result_7.png', img) -------------------------------------------------------------------------------- /Assignment02/5_dice.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | from time import sleep 3 | from termcolor import colored 4 | while True: 5 | temp=randint(1,6) 6 | if temp==6: 7 | print('%i . lets Dice again!' %(temp)) 8 | sleep(2) 9 | else: 10 | playagain=input('%i .wanna play again?(y/n) ' %(temp)) 11 | if playagain=='n': 12 | break 13 | print(colored('You are out of Dice program.', 'red')) 14 | -------------------------------------------------------------------------------- /Assignment21/1_checkered_board.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | img_arr = np.arange(0, 640000, 1, np.uint8) 5 | img_arr = np.reshape(img_arr, (800, 800)) 6 | height, width = img_arr.shape 7 | 8 | for i in range(height): 9 | for j in range(width): 10 | if ((i//(width/8))%2+(j//(width/8))%2)%2==0: 11 | img_arr[i][j]=255 12 | else: 13 | img_arr[i][j]=0 14 | 15 | cv2.imwrite('result_1.png', img_arr) -------------------------------------------------------------------------------- /Assignment08/3_diamond.py: -------------------------------------------------------------------------------- 1 | n = int(input('Enter number of rows: ')) 2 | stars = 1 3 | for i in range(n): 4 | for j in range(n-i-1): 5 | print(end=' ') 6 | for k in range(stars): 7 | print('*', end='') 8 | stars+=2 9 | print() 10 | stars = n*2-3 11 | for i in range(1, n): 12 | for j in range(0, i): 13 | print(end=' ') 14 | for k in range(stars): 15 | print('*', end='') 16 | stars-=2 17 | print() 18 | -------------------------------------------------------------------------------- /Assignment10-Mini Project/film.py: -------------------------------------------------------------------------------- 1 | import media 2 | class Film(media.Media): 3 | def __init__(self, CATEGORY, NAME, DIRECTOR, IMDBSCORE, URL, DURATION, CASTS, GENRE): 4 | super().__init__(CATEGORY, NAME, DIRECTOR, IMDBSCORE, URL, DURATION, CASTS) 5 | self.genre = GENRE 6 | def showInfo(self): 7 | super().showInfo() 8 | print('genre: %s'%self.genre) 9 | def edit(self): 10 | super().edit() 11 | self.genre = input('New Genre: ') -------------------------------------------------------------------------------- /Assignment10-Mini Project/clip.py: -------------------------------------------------------------------------------- 1 | import media 2 | class Clip(media.Media): 3 | def __init__(self, CATEGORY, NAME, DIRECTOR, IMDBSCORE, URL, DURATION, CASTS, SUBJECT): 4 | super().__init__(CATEGORY, NAME, DIRECTOR, IMDBSCORE, URL, DURATION, CASTS) 5 | self.subject = SUBJECT 6 | def showInfo(self): 7 | super().showInfo() 8 | print('subject: %s'%(self.subject)) 9 | def edit(self): 10 | super().edit() 11 | self.subject = input('New Subject: ') -------------------------------------------------------------------------------- /Assignment10-Mini Project/db.csv: -------------------------------------------------------------------------------- 1 | film,tenet,Christopher Nolan,7.4,https://www.youtube.com/watch?v=AZGcmvrTX9M,150,john david washington-robert pattinson-elizabeth debicki,action-scifi 2 | series,dexter,Manos Jr,8.6,https://www.youtube.com/watch?v=hA-oCTUrNfE,45,david zayas-jennifer carpenter,5,12,crime 3 | documentary,cosmos,Neil deGeasse Tyson,9.3,https://www.youtube.com/watch?v=_erVOAbz420,60,NA,10y,A Spacetime Odyssey 4 | clip,takedel,karim,NA,https://www.youtube.com/watch?v=nFtuSkRepvo,2,karim-karim's friends,fun 5 | -------------------------------------------------------------------------------- /Assignment14/T-rex runner/cactus.py: -------------------------------------------------------------------------------- 1 | import random 2 | import arcade 3 | class Cactus(arcade.Sprite): 4 | def __init__(self, width, height, speed): 5 | super().__init__() 6 | self.pic_path = random.choice(['images/cactus1_night.png','images/cactus4_night.png']) 7 | self.texture = arcade.load_texture(self.pic_path) 8 | self.center_x = width 9 | self.center_y = 164 10 | self.change_x = speed #-4 11 | self.change_y = 0 12 | self.width = 100 13 | self.height = 100 -------------------------------------------------------------------------------- /Assignment05/1_khayamPaskalTriangle.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | triangleList = [] 3 | for i in range(n): 4 | temp = [] 5 | if i == 0: 6 | temp.append(1) 7 | else: 8 | for j in range(i+1): 9 | if j==0 or j==i: 10 | temp.append(triangleList[i-1][j-1]) 11 | else: 12 | temp.append(triangleList[i-1][j]+triangleList[i-1][j-1]) 13 | triangleList.append(temp) 14 | for i in range(n): 15 | for j in range(i+1): 16 | print(triangleList[i][j], end=' ') 17 | print() 18 | -------------------------------------------------------------------------------- /Assignment14/README.md: -------------------------------------------------------------------------------- 1 | ## T-rex runner 2 | - [x] Jump over cacti 3 | - [x] Bending in the face of birds 4 | - [x] jump sound 5 | - [x] Day and Night mode 6 | - [x] Speed up the game over time 7 | - [x] The current score is displayed next to the highest score 8 | - Trex view 1 9 | - ![Screenshot (486)](https://user-images.githubusercontent.com/77120507/134362351-3ae93ba5-b88b-4003-a292-37731621bb30.png) 10 | - Trex view 2 11 | - ![Screenshot (492)](https://user-images.githubusercontent.com/77120507/134362477-bf5d6f8c-c886-4c80-9d0e-2e5e80f1b5d1.png) 12 | -------------------------------------------------------------------------------- /Assignment14/T-rex runner/ground.py: -------------------------------------------------------------------------------- 1 | import random 2 | import arcade 3 | class Ground(arcade.Sprite): 4 | def __init__(self, width, height): 5 | super().__init__() 6 | self.pic_path = random.choice(['images/ground0.png','images/ground1.png', 'images/ground2.png', 'images/ground3.png', 'images/ground4.png']) 7 | self.texture = arcade.load_texture(self.pic_path) 8 | self.center_x = width 9 | self.center_y = height 10 | self.change_x = -4 11 | self.change_y = 0 12 | self.width = 64 13 | self.height = 64 -------------------------------------------------------------------------------- /Assignment14/T-rex runner/pterodactyl.py: -------------------------------------------------------------------------------- 1 | import random 2 | import arcade 3 | class Pterodactyl(arcade.AnimatedWalkingSprite): 4 | def __init__(self, width, height, speed): 5 | super().__init__() 6 | self.walk_left_textures = [arcade.load_texture('images/pterodactyl0.png'), arcade.load_texture('images/pterodactyl1.png')] 7 | self.center_x = width 8 | self.center_y = random.randint(300, 400) 9 | self.change_x = speed #-5 10 | self.change_y = 0 11 | # self._width = 50 12 | # self.height = 50 13 | self.scale = 0.7 -------------------------------------------------------------------------------- /Assignment10-Mini Project/documentary.py: -------------------------------------------------------------------------------- 1 | import media 2 | class Documentary(media.Media): 3 | def __init__(self, CATEGORY, NAME, DIRECTOR, IMDBSCORE, URL, DURATION, CASTS, TIME_SPEND, SUBJECT): 4 | super().__init__(CATEGORY, NAME, DIRECTOR, IMDBSCORE, URL, DURATION, CASTS) 5 | self.timeSpend = TIME_SPEND 6 | self.subject = SUBJECT 7 | def showInfo(self): 8 | super().showInfo() 9 | print('subject: %s\ntime spend to make: %s'%(self.subject, self.timeSpend)) 10 | def edit(self): 11 | super().edit() 12 | self.timeSpend = input('New Time spend: ') 13 | self.subject = input('New Subject: ') -------------------------------------------------------------------------------- /Assignment04/3_multiplicationTable.py: -------------------------------------------------------------------------------- 1 | from colorama import Fore, Style 2 | n, m = map(int, input().split()) 3 | print('\n x ', end=' ') 4 | for k in range(1, m+1): 5 | print(Fore.YELLOW + str(k).zfill(2), end=' ') 6 | print('\n') 7 | print(Style.RESET_ALL, end='') 8 | for i in range(1, n+1): 9 | print(Fore.YELLOW + str(i).zfill(2), end=' ') 10 | print(Style.RESET_ALL, end='') 11 | for j in range(1, m+1): 12 | if i==j: 13 | print(Fore.YELLOW + str(i*j).zfill(2), end=' ') 14 | print(Style.RESET_ALL, end='') 15 | else: 16 | print(str(i*j).zfill(2), end=' ') 17 | print('\n') 18 | -------------------------------------------------------------------------------- /Assignment11/complex loops/main.py: -------------------------------------------------------------------------------- 1 | import arcade 2 | COLUMN_SPACING = 20 3 | ROW_SPACING = 20 4 | LEFT_MARGIN = 110 5 | BOTTOM_MARGIN = 110 6 | arcade.open_window(400, 400, "Complex Loops - Box") 7 | arcade.set_background_color(arcade.color.WHITE) 8 | arcade.start_render() 9 | for row in range(10): 10 | for column in range(10): 11 | x = column * COLUMN_SPACING + LEFT_MARGIN 12 | y = row * ROW_SPACING + BOTTOM_MARGIN 13 | if (row+column)%2==0: 14 | arcade.draw_circle_filled(x, y, 7, arcade.color.RED) 15 | else: 16 | arcade.draw_circle_filled(x, y, 7, arcade.color.BLUE) 17 | arcade.finish_render() 18 | arcade.run() -------------------------------------------------------------------------------- /Assignment05/3_turtle.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | turtle.title("Benyamin\'s Turtle ^^") 3 | t = turtle.Pen() 4 | t.shape("turtle") 5 | t.speed(2.5) 6 | turtle.bgcolor('white') 7 | t.penup() 8 | t.pendown() 9 | i, j= 0, 0 10 | side=0 11 | while i < 10: 12 | t.left(180-((((i+3-2)*180)/(i+3))/2)) 13 | side=106+side 14 | while j <= i+2: 15 | t.pencolor('black') 16 | t.width(1.5) 17 | t.forward(side/(i+3)) 18 | t.left(180-(((i+3-2)*180)/(i+3))) 19 | j += 1 20 | t.penup() 21 | t.right(180-(((i+3-2)*180)/(i+3))) 22 | t.right((((i+3-2)*180)/(i+3))/2) 23 | t.forward(17) 24 | t.pendown() 25 | j=0 26 | i+=1 27 | -------------------------------------------------------------------------------- /Assignment10-Mini Project/series.py: -------------------------------------------------------------------------------- 1 | import media 2 | class Series(media.Media): 3 | def __init__(self, CATEGORY, NAME, DIRECTOR, IMDBSCORE, URL, DURATION, CASTS, SEASON, EPISODE, GENRE): 4 | super().__init__(CATEGORY, NAME, DIRECTOR, IMDBSCORE, URL, DURATION, CASTS) 5 | self.season = SEASON 6 | self.episode = EPISODE 7 | self.genre = GENRE 8 | def showInfo(self): 9 | super().showInfo() 10 | print('genre: %s\nseason: %s\nepisod per season: %s'%(self.genre, self.season, self.episode)) 11 | def edit(self): 12 | super().edit() 13 | self.season = input('New Season: ') 14 | self.episode = input('New Episode: ') 15 | self.genre = input('New Genre: ') -------------------------------------------------------------------------------- /Assignment19/commands.sql: -------------------------------------------------------------------------------- 1 | --Insert data to Customers table 2 | INSERT INTO Customers (id, name, city, country) 3 | VALUES(001, 'Benyamin', 'mashhad', 'IR') 4 | INSERT INTO Customers (id, name, city, country) 5 | VALUES(002, 'bob', 'newyork', 'USA') 6 | 7 | --Insert data to Products table 8 | INSERT INTO Products (id, name, price, count) 9 | VALUES(001, 'glue', 1000, 380) 10 | INSERT INTO Products (id, name, price, count) 11 | VALUES(002, 'cable', 55000, 610) 12 | 13 | --Select available products 14 | SELECT * FROM Products WHERE count!=0 15 | 16 | --Delete foreign customers 17 | DELETE FROM Customers WHERE country!='IR' 18 | 19 | --Update price of all goods 20 | UPDATE Products 21 | SET price = price*80/100 22 | WHERE count!=0 23 | -------------------------------------------------------------------------------- /Assignment12/READme.md: -------------------------------------------------------------------------------- 1 | ## Silver Spacecraft 2 | - Silver Spacecraft in **Python** using **Arcade** library. 3 | - [x] when bullet hit enemy spacecraft they will explode. 4 | - [x] enemy will come between 2-6 sec randomly. 5 | - [x] when enemy or list disappear from the screen their object will be remove. 6 | - [x] show 3 heart in bottom left. 7 | - [x] show score in bottom right. 8 | - [x] show Game over when user lose all their health. 9 | - [x] play sound when shooting. 10 | - [x] play sound when enemy spacecraft explode. 11 | - [x] spacecraft can move in x and y and change angle. 12 | - space craft view 13 | - ![Silver Spacecraft](https://user-images.githubusercontent.com/77120507/133397753-32b502ed-78c4-45ac-bb44-f09c2597d0e5.png) 14 | -------------------------------------------------------------------------------- /Assignment04/2_quadraticEquation.py: -------------------------------------------------------------------------------- 1 | from math import sqrt 2 | import re 3 | def deltaFucn(a,b,c): 4 | return ((b**2)-4*(a*c)) 5 | def quadraticEquationFuc(a,b,c): 6 | delta=deltaFucn(a,b,c) 7 | if delta<0: 8 | print('No answer.') 9 | elif delta==0: 10 | print('answer: %f' %((-b)/(2*a))) 11 | else: 12 | print('answer: %f answer: %f' %(((-b)+sqrt(delta))/(2*a), ((-b)-sqrt(delta))/(2*a))) 13 | equationStr = input('Give me a Quadratic Equation: e.g. ax^2+bx+c=0\n') 14 | equationList = re.split('\+|\^|x|\=', equationStr) 15 | equationList = list(filter(None, equationList)) 16 | equationList.pop(1) 17 | equationList = list(map(int, equationList)) 18 | if equationList[3]!=0: 19 | equationList[2]-=equationList[3] 20 | quadraticEquationFuc(equationList[0], equationList[1], equationList[2]) 21 | -------------------------------------------------------------------------------- /Assignment19/Palam_Polom_Pilish.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | choice_list = ['✋', '🤚'] 4 | score = [0, 0, 0] # pc1-pc2-user 5 | for i in range(5): 6 | pc1 = choice(choice_list) 7 | pc2 = choice(choice_list) 8 | user = input('choose between ✋/🤚: ') 9 | if pc1==pc2==user: 10 | print(f'pc1{pc1} pc2{pc2} you{user} - draw') 11 | elif pc1==pc2: 12 | print(f'pc1{pc1} pc2{pc2} you{user} - user+') 13 | score[2]+=1 14 | elif pc1==user: 15 | print(f'pc1{pc1} pc2{pc2} you{user} - pc2+') 16 | score[1]+=1 17 | elif pc2==user: 18 | print(f'pc1{pc1} pc2{pc2} you{user} - pc1+') 19 | score[0]+=1 20 | winner = score.index(max(score)) 21 | if winner==0: 22 | print('pc1 win.') 23 | elif winner==1: 24 | print('pc2 win.') 25 | else: 26 | print('you win.') -------------------------------------------------------------------------------- /Assignment08/6_complexNumbers.py: -------------------------------------------------------------------------------- 1 | import re 2 | def sum(x, y): 3 | result = {} 4 | result['r']=x['r']+y['r'] 5 | result['i']=x['i']+y['i'] 6 | return result 7 | def sub(x, y): 8 | result = {} 9 | result['r']=x['r']-y['r'] 10 | result['i']=x['i']-y['i'] 11 | return result 12 | def mul(x, y): 13 | result = {} 14 | result['r']=x['r']*y['r']-x['i']*y['i'] 15 | result['i']=x['i']*y['r']+x['r']*y['i'] 16 | return result 17 | def show(x): 18 | return str(x['r'])+'+('+str(x['i'])+')i' 19 | c1list = list(map(int, re.sub(r'^(\d+)[\+ \-](\d+)i$', '\g<1>\g<2>', input('complex number1: e.g. 2+3i\n')))) 20 | c2list = list(map(int, re.sub(r'^(\d+)[\+ \-](\d+)i$', '\g<1>\g<2>', input('complex number2: e.g. 2+3i\n')))) 21 | c1 = {'r':c1list[0], 'i':c1list[1]} 22 | c2 = {'r':c2list[0], 'i':c2list[1]} 23 | print('sum: %s\tsub: %s\tmul: %s'%(show(sum(c1, c2)), show(sub(c1, c2)), show(mul(c1, c2)))) 24 | -------------------------------------------------------------------------------- /Assignment20/to do/database.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | con = sqlite3.connect('db.db') 4 | my_cursor = con.cursor() 5 | 6 | def add(id, title, description, time): 7 | my_cursor.execute(f'INSERT INTO tasks(id, title, description, time, done, priority) VALUES("{id}", "{title}", "{description}", "{time}", "{0}", "{0}")') 8 | con.commit() 9 | 10 | def get_all(): 11 | my_cursor.execute('SELECT * FROM tasks') 12 | result = my_cursor.fetchall() 13 | return result 14 | 15 | def get_detail(id): 16 | my_cursor.execute(f'SELECT * FROM tasks WHERE id={id}') 17 | result = my_cursor.fetchall() 18 | return result 19 | 20 | def delete(id): 21 | my_cursor.execute(f'DELETE FROM tasks WHERE id={id}') 22 | con.commit() 23 | 24 | def update_priority(id, state): 25 | my_cursor.execute(f'UPDATE tasks SET priority = {state} WHERE id={id}') 26 | con.commit() 27 | 28 | def update_done(id, state): 29 | my_cursor.execute(f'UPDATE tasks SET done = {state} WHERE id={id}') 30 | con.commit() -------------------------------------------------------------------------------- /Assignment08/4_fraction.py: -------------------------------------------------------------------------------- 1 | import re 2 | def sum(x, y): 3 | result = {} 4 | result['s'] = x['s'] * y['m'] + x['m'] * y['s'] 5 | result['m'] = x['m'] * y['m'] 6 | return result 7 | def sub(x, y): 8 | result = {} 9 | result['s'] = x['s'] * y['m'] - x['m'] * y['s'] 10 | result['m'] = x['m'] * y['m'] 11 | return result 12 | def mul(x, y): 13 | result = {} 14 | result['s'] = x['s'] * y['s'] 15 | result['m'] = x['m'] * y['m'] 16 | return result 17 | def div(x, y): 18 | result = {} 19 | result['s'] = x['s'] * y['m'] 20 | result['m'] = x['m'] * y['s'] 21 | return result 22 | def show(x): 23 | return str(x['s'])+'/'+str(x['m']) 24 | a = {} 25 | b = {} 26 | aList= list(map(int, re.sub(r'^(\d+)/(\d+)', '\g<1>\g<2>', input('give me fraction1: e.g. 3/5\n')))) 27 | bList= list(map(int, re.sub(r'^(\d+)/(\d+)', '\g<1>\g<2>', input('give me fraction2: e.g. 3/5\n')))) 28 | a = {'s':aList[0],'m':aList[1]} 29 | b = {'s':bList[0],'m':bList[1]} 30 | print('sum: %s\tsub: %s\tmul: %s\tdiv: %s'%(show(sum(a, b)), show(sub(a, b)), show(mul(a, b)), show(div(a, b)))) 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Benyamin Zojaji 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Assignment20/README.md: -------------------------------------------------------------------------------- 1 | ## To-Do list 2 | - GUI to-do list written in **python** designed with **pyqt** and using **sqlite** database. 3 | - feautures: 4 | - [x] Detail button with unique window. 5 | - [x] Delete task. 6 | - [x] Add new task. 7 | - [x] Pin important tasks for higher priority. 8 | - [x] Designed with 2 tabs for better user experience, all-tasks and Done tasks. 9 | - views: 10 | - ![todolist1](https://user-images.githubusercontent.com/77120507/139032396-c6a5e1d3-2abb-48a0-89c8-099972497726.png) 11 | - ![todolist2](https://user-images.githubusercontent.com/77120507/139032429-4027b4c2-b2a2-4699-8a83-05e104f6c022.png) 12 | - ![todolist3](https://user-images.githubusercontent.com/77120507/139032452-78f46f5d-07c1-41d4-9573-d02cc2676ef4.png) 13 | 14 | ## AI Snake 15 | - A clever snake that can find the apple! 16 | - Written in **python** using **arcade** library. 17 | - view: 18 | - ![AIsnake](https://user-images.githubusercontent.com/77120507/139032617-a3edb07e-02d0-4499-a553-f89e5f0b79ac.png) 19 | 20 | ## Telegram Bot 21 | - a telegram bot written in **python** using **py-telegrambot-api**. 22 | - New feature: 23 | - added /note to bot commands. 24 | -------------------------------------------------------------------------------- /Assignment18/Password generator/main.py: -------------------------------------------------------------------------------- 1 | import string 2 | import secrets 3 | from PySide6.QtWidgets import * 4 | from PySide6.QtUiTools import * 5 | from PySide6.QtCore import * 6 | 7 | 8 | class MainWindow(QMainWindow): 9 | def __init__(self): 10 | super().__init__() 11 | loader = QUiLoader() 12 | self.ui = loader.load('passwordGenerator.ui', None) 13 | self.ui.show() 14 | 15 | self.ui.generate_btn.clicked.connect(self.generate) 16 | 17 | def generate(self): 18 | if self.ui.rd_weak.isChecked(): 19 | alphabet = string.ascii_letters 20 | password = ''.join(secrets.choice(alphabet) for i in range(8)) 21 | elif self.ui.rd_good.isChecked(): 22 | alphabet = string.ascii_letters + string.digits 23 | password = ''.join(secrets.choice(alphabet) for i in range(10)) 24 | elif self.ui.rd_unbreakable.isChecked(): 25 | alphabet = string.ascii_letters + string.digits + string.punctuation 26 | password = ''.join(secrets.choice(alphabet) for i in range(12)) 27 | self.ui.lineEdit.setText(password) 28 | 29 | 30 | app = QApplication([]) 31 | window = MainWindow() 32 | app.exec() -------------------------------------------------------------------------------- /Assignment03/1_simpleHangman.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from random import choice 3 | from time import sleep 4 | def findAllSubIndexes(a_str, sub): 5 | start = 0 6 | while True: 7 | start = a_str.find(sub, start) 8 | if start == -1: return 9 | yield start 10 | start += len(sub) 11 | wordSite = "https://www.mit.edu/~ecprice/wordlist.10000" 12 | response = requests.get(wordSite) 13 | WORDS = list(response.content.splitlines()) 14 | WORDS = list(map(lambda i: i.decode(), WORDS)) 15 | while True: # beacuse the list has many words like 'aba'! which is not feeling good 16 | pcWord = choice(WORDS).lower() 17 | if len(pcWord)>3: 18 | break 19 | health = 10 20 | outputWord=(len(pcWord)*'-') 21 | while '-' in outputWord and health>0: 22 | print(('\n%s HP:%s') %(outputWord,health)) 23 | sleep(0.5) 24 | userInput=input('Give me single char: ')[0].lower() 25 | showIndexes=list(findAllSubIndexes(pcWord, userInput)) 26 | if showIndexes: 27 | for i in showIndexes: 28 | outputWord=outputWord[:i]+pcWord[i]+outputWord[i+1:] 29 | else: 30 | health-=1 31 | print('nah! there is no %s in my word' %userInput) 32 | sleep(0.5) 33 | print('\n%s is correct. well done! Dont tell anyone you are an engenius.\n'%pcWord) if not '-' in outputWord else print('\nLOSER!\n') 34 | -------------------------------------------------------------------------------- /Assignment18/Guess the number/main.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | from PySide6.QtWidgets import * 3 | from PySide6.QtUiTools import * 4 | from PySide6.QtCore import * 5 | 6 | 7 | class MainWindow(QMainWindow): 8 | def __init__(self): 9 | super().__init__() 10 | loader = QUiLoader() 11 | self.ui = loader.load('guessTheNumber.ui', None) 12 | self.ui.show() 13 | 14 | self.randomNumber = randint(0, 99) 15 | 16 | self.ui.check_btn.clicked.connect(self.check) 17 | self.ui.newgame_btn.clicked.connect(self.newGame) 18 | 19 | def check(self): 20 | userGuess = self.ui.lineEdit.text() 21 | if userGuess!='': 22 | try: 23 | if int(userGuess)==self.randomNumber: 24 | self.ui.guide_label.setText('That\'s right') 25 | elif int(userGuess)>self.randomNumber: 26 | self.ui.guide_label.setText('lower') 27 | elif int(userGuess)scores['user']: 37 | print('computer wins.') 38 | elif scores['computer']=60: 7 | result['s']-=60 8 | result['m']+=1 9 | if result['m'] >=60: 10 | result['m']-=60 11 | result['h']+=1 12 | if result['h']>23: 13 | result['h']-=24 14 | return result 15 | def sub(x, y): 16 | result = {} 17 | result['s'] = x['s'] - y['s'] 18 | result['m'] = x['m'] - y['m'] 19 | result['h'] = x['h'] - y['h'] 20 | if result['s']<0: 21 | result['m']-=1 22 | result['s']+=60 23 | if result['m']<0: 24 | result['h']-=1 25 | result['m']+=60 26 | return result 27 | def timeToSec(x): 28 | return x['h']*3600 + x['m']*60 + x['s'] 29 | def secToTime(x): 30 | result = {} 31 | result['h'] = x//3600 32 | result['m'] = (x%3600)//60 33 | result['s'] = (x%3600)%60 34 | return result 35 | def show(x): 36 | return str(x['h'])+':'+str(x['m'])+':'+str(x['s']) 37 | t1list = list(map(int, input('time1: e.g. 2:16:18\n').split(':'))) 38 | t2list = list(map(int, input('time2: e.g. 2:16:18\n').split(':'))) 39 | sec = int(input('give me sec convert to time: ')) 40 | t1 = {'h':t1list[0], 'm':t1list[1], 's':t1list[2]} 41 | t2 = {'h':t2list[0], 'm':t2list[1], 's':t2list[2]} 42 | print('sum: %s\tsub: %s\ttimeToSec: %s\tsecToTime: %s'%(show(sum(t1, t2)), show(sub(t1, t2)), timeToSec(t1), show(secToTime(sec)))) 43 | -------------------------------------------------------------------------------- /Assignment09/1_fractionsUsingClass.py: -------------------------------------------------------------------------------- 1 | class Fraction: 2 | def __init__(self, numerator=None, denumerator=None): 3 | self.numerator = numerator 4 | self.denumerator = denumerator 5 | def sum(self, frac): 6 | result = Fraction() 7 | result.numerator = self.numerator*frac.denumerator + self.denumerator*frac.numerator 8 | result.denumerator = self.denumerator*frac.denumerator 9 | return result 10 | def mul(self, frac): 11 | result = Fraction() 12 | result.numerator = self.numerator*frac.numerator 13 | result.denumerator = self.denumerator*frac.denumerator 14 | return result 15 | def div(self, frac): 16 | result = Fraction() 17 | result.numerator = self.numerator*frac.denumerator 18 | result.denumerator = self.denumerator*frac.numerator 19 | return result 20 | def sub(self, frac): 21 | result = Fraction() 22 | result.numerator = self.numerator*frac.denumerator - self.denumerator*frac.numerator 23 | result.denumerator = self.denumerator*frac.denumerator 24 | return result 25 | def show(self): 26 | return str(self.numerator) + '/' + str(self.denumerator) 27 | aList= list(map(int, input('give me fraction1: e.g. 3/5\n').split('/'))) 28 | bList= list(map(int, input('give me fraction2: e.g. 3/5\n').split('/'))) 29 | a = Fraction(aList[0], aList[1]) 30 | b = Fraction(bList[0], bList[1]) 31 | print('sum: %s\tsub: %s\tmul: %s\tdiv: %s'%((a.sum(b)).show(), (a.sub(b)).show(), (a.mul(b)).show(), (a.div(b)).show())) 32 | -------------------------------------------------------------------------------- /Assignment18/Translator En-Fa/main.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtWidgets import * 2 | from PySide6.QtUiTools import * 3 | from PySide6.QtCore import * 4 | from googletrans import Translator 5 | 6 | class MainWindow(QMainWindow): 7 | def __init__(self): 8 | super().__init__() 9 | loader = QUiLoader() 10 | self.ui = loader.load('translator.ui', None) 11 | self.ui.show() 12 | 13 | self.ui.translate_btn.clicked.connect(self.translate_func) 14 | self.ui.lang_btn.clicked.connect(self.langChange) 15 | 16 | def langChange(self): 17 | if self.ui.lang_btn.text()=='En -> Fa': 18 | self.ui.lang_btn.setText('Fa -> En') 19 | else: 20 | self.ui.lang_btn.setText('En -> Fa') 21 | 22 | def translate_func(self): 23 | try: 24 | if self.ui.srcText.text()!='': 25 | translator = Translator() 26 | if self.ui.lang_btn.text()=='En -> Fa': 27 | translate_text = translator.translate(self.ui.srcText.text(), src='en', dest='fa') 28 | else: 29 | translate_text = translator.translate(self.ui.srcText.text(), src='fa', dest='en') 30 | self.ui.destText.setText(translate_text.text) 31 | else: 32 | self.ui.destText.setText('') 33 | msgBox = QMessageBox() 34 | msgBox.setText('There is nothing to translate.') 35 | msgBox.exec() 36 | except: 37 | self.ui.destText.setText('Connection Error') 38 | 39 | app = QApplication([]) 40 | window = MainWindow() 41 | app.exec() -------------------------------------------------------------------------------- /Assignment21/README.md: -------------------------------------------------------------------------------- 1 | ## Checkered Board 2 | - Create a chess table using **numpy** and **opencv**. 3 | - view: 4 | - ![result_1](https://user-images.githubusercontent.com/77120507/139427129-565d93a9-97eb-44bb-b261-0a3c5d1a6164.png) 5 | ## Color Correction 6 | - Reverse black and white colors with opencv. 7 | - views: 8 | - ![result_2_1](https://user-images.githubusercontent.com/77120507/139427174-2e5f3403-fae6-44b4-b560-76f76b8014f7.png) 9 | - ![result_2_2](https://user-images.githubusercontent.com/77120507/139427186-fbc246f3-1e6a-4648-9e0e-cdcccaff4c27.png) 10 | ## Rotate Image 11 | - Rotate an image with for loop in opencv(without cv2.rotate) 12 | - view: 13 | - ![result_3](https://user-images.githubusercontent.com/77120507/139427258-d31aafcc-0fc7-4706-8334-c9a011ab0ca1.png) 14 | ## Color Separation 15 | - Separate object of black-whte image using opencv and threshold method. 16 | - view: 17 | - ![result_4](https://user-images.githubusercontent.com/77120507/139429837-e7538f85-af2c-4f25-9ed3-7dd9a28d2fed.png) 18 | ## Corner Line 19 | - Create a black line in top left corner.(without opencv built-in methods) 20 | - view: 21 | - ![result_5](https://user-images.githubusercontent.com/77120507/139429884-e7c9eb8a-a124-4232-ab79-b4e3a5f42468.png) 22 | ## Gradient 23 | - Create an image with whito-black gradient using **open-cv** and **numpy**. 24 | - view: 25 | - ![result_6](https://user-images.githubusercontent.com/77120507/139590566-7a676885-cb49-43a3-89d1-fa3d02c9386a.png) 26 | ## Letter B 27 | - Design letter-B using **numpy** and **open-cv**. 28 | - view: 29 | - ![result_7](https://user-images.githubusercontent.com/77120507/139590558-05787f52-7c96-4669-ad1a-4a1050380378.png) 30 | 31 | -------------------------------------------------------------------------------- /Assignment14/T-rex runner/dino.py: -------------------------------------------------------------------------------- 1 | import arcade 2 | class Dino(arcade.AnimatedWalkingSprite): 3 | def __init__(self): 4 | super().__init__() 5 | self.stand_right_textures = [arcade.load_texture('images/dino.png')] 6 | self.walk_right_textures = [arcade.load_texture('images/walk0.png'), arcade.load_texture('images/walk1.png')] 7 | self.walk_down_textures = [arcade.load_texture('images/down0.png'), arcade.load_texture('images/down0.png')] 8 | self.walk_up_textures = [arcade.load_texture('images/dino.png')] 9 | self.center_x = 150 10 | self.center_y = 250 11 | self.width = 10 12 | self.height = 20 13 | self.scale = 1 14 | self.change_x = 0.5 15 | self.change_y = 0 16 | self.down_frame = 0 17 | try: 18 | myFile = open('db/high_score.txt', 'r') 19 | self.highScore = int(myFile.read()) 20 | myFile.close() 21 | except: 22 | self.highScore = 0 23 | self.score = 0 24 | self.score_speed = 0 25 | self.down = False 26 | def set_x(self): 27 | self.center_x = 150 28 | def write_highScore(self): 29 | myFile = open('db/high_score.txt', 'w') 30 | myFile.write('%s' %self.score) 31 | myFile.close() 32 | def jump_sound(self): 33 | arcade.play_sound(arcade.sound.Sound(':resources:sounds/phaseJump1.wav'), 1.0, 0.0,False) 34 | def manual_walkDown_animation(self): 35 | if self.down_frame <= 10: 36 | self.texture = arcade.load_texture('images/down0.png') 37 | elif self.down_frame <= 20: 38 | self.texture = arcade.load_texture('images/down1.png') 39 | else: 40 | self.down_frame = 0 41 | -------------------------------------------------------------------------------- /Assignment10-Mini Project/media.py: -------------------------------------------------------------------------------- 1 | import actor 2 | import pytube 3 | import qrcode 4 | class Media: 5 | def __init__(self, CATEGORY, NAME, DIRECTOR, IMDBSCORE, URL, DURATION, CASTS): 6 | self.name = NAME 7 | self.category = CATEGORY 8 | self.director = DIRECTOR 9 | self.imdbScore = IMDBSCORE 10 | self.url = URL 11 | self.duration = DURATION 12 | self.casts = [] 13 | for act in CASTS.split('-'): 14 | self.casts.append(actor.Actor(act)) 15 | def showInfo(self): 16 | print('-------------------------------------') 17 | print('name: %s\ncategory: %s\ndirector: %s\nimdb: %s\nurl: %s\nduration: %s' %(self.name, self.category, self.director, self.imdbScore, self.url, self.duration)) 18 | print('Actors list: ',end='') 19 | tmp = [] 20 | for i in self.casts: 21 | tmp.append(i.name) 22 | print('-'.join(tmp)) 23 | def download(self): 24 | link = self.url 25 | first_stream = pytube.YouTube(link).streams.first() 26 | first_stream.download(output_path='./', filename='downloaded.mp4') 27 | def qrcode(self): 28 | img = qrcode.make(self.category+","+self.name+","+self.url) 29 | img.save('qrcode/'+self.name+'.png') 30 | def get_casts(self): 31 | tmp = [] 32 | for act in self.casts: 33 | tmp.append(act.name) 34 | return '-'.join(tmp) 35 | def edit(self): 36 | self.name = input('New Name: ') 37 | self.director = input('New Director: ') 38 | self.imdbScore = input('New Imdb: ') 39 | self.url = input('New Url: ') 40 | self.duration = input('New Duration: ') 41 | CASTS = input('New Casts: ') 42 | self.casts = [] 43 | for act in CASTS.split('-'): 44 | self.casts.append(actor.Actor(act)) -------------------------------------------------------------------------------- /Assignment09/2_timeUsingClass.py: -------------------------------------------------------------------------------- 1 | class Time: 2 | def __init__(self, hour=None, minute=None, second=None): 3 | self.hour = hour 4 | self.minute = minute 5 | self.second = second 6 | def sum(self, time): 7 | result = Time() 8 | result.second = self.second + time.second 9 | result.minute = self.minute + time.minute 10 | result.hour = self.hour + time.hour 11 | if result.second>=60: 12 | result.second-=60 13 | result.minute+=1 14 | if result.minute>=60: 15 | result.minute-=60 16 | result.hour+=1 17 | return result 18 | def sub(self, time): 19 | result = Time() 20 | result.second = self.second - time.second 21 | result.minute = self.minute - time.minute 22 | result.hour = self.hour - time.hour 23 | if result.second<0: 24 | result.minute-=1 25 | result.second+=60 26 | if result.minute<0: 27 | result.hour-=1 28 | result.minute+=60 29 | return result 30 | def secToTime(self): 31 | result = Time() 32 | result.hour = self.second//3600 33 | result.minute = (self.second%3600)//60 34 | result.second = (self.second%3600)%60 35 | return result 36 | def timeToSec(self): 37 | return self.hour*3600 + self.minute*60 + self.second 38 | def show(self): 39 | return str(self.hour)+':'+str(self.minute)+':'+str(self.second) 40 | t1list = list(map(int, input('time1: e.g. 2:16:18\n').split(':'))) 41 | t2list = list(map(int, input('time2: e.g. 2:16:18\n').split(':'))) 42 | sec = Time(0 ,0 ,int(input('give me sec convert to time: '))) 43 | t1 = Time(t1list[0], t1list[1], t1list[2]) 44 | t2 = Time(t2list[0], t2list[1], t2list[2]) 45 | print('sum: %s\tsub: %s\ttimeToSec: %s\tsecToTime: %s'%((t1.sum(t2)).show(), t1.sub(t2).show(), t1.timeToSec(), (sec.secToTime()).show())) 46 | -------------------------------------------------------------------------------- /Assignment18/README.md: -------------------------------------------------------------------------------- 1 | ## Sudoku 2 | - Sudoku game written in **Python** using **Pyside6**. 3 | - features: 4 | - [x] check sudoku while you are playing it. 5 | - [x] dark mode on/off 6 | - [x] text align 7 | - [x] error handling when data missing 8 | - [x] make main numbers read-only 9 | - [x] win check 10 | - views: 11 | - ![sudoku1](https://user-images.githubusercontent.com/77120507/137157822-c7e2eec3-73a4-450a-b089-4bba6aeb0785.png) 12 | - ![sudoku2](https://user-images.githubusercontent.com/77120507/137157874-f0c4a332-87ac-4a70-9731-b1356f20ba96.png) 13 | - ![sudoku3](https://user-images.githubusercontent.com/77120507/137157902-5c2b2055-d6e0-4ef2-931c-bd69eec62e54.png) 14 | 15 | ## Unit Converter 16 | - Simple GUI unit converter written in **Python** using **Pyside** and **unit_converter**. 17 | - features: 18 | - [x] Support Length - Mass - Value - Temperature 19 | - view: 20 | - ![unitConverter](https://user-images.githubusercontent.com/77120507/137158223-108c61d7-77e5-43b6-a676-0ebbbbe1eb4c.png) 21 | 22 | ## Guess the number 23 | - A simple game written in **Python** using **PySide6**. 24 | - view: 25 | - ![guessTheNumber](https://user-images.githubusercontent.com/77120507/136650010-5bcb6f2e-d9ab-42f9-8f6c-90eebf441af6.png) 26 | ## Password Generator 27 | - Password Generator app written in **Python** using **PySide6**. 28 | - features: 29 | - [x] Three modes for generating passwords. weak, normal and unbreakable 30 | - view: 31 | - ![passwordGenerator](https://user-images.githubusercontent.com/77120507/136650056-ff51b41d-9b22-4e60-98ab-54688f80f575.png) 32 | ## Translator 33 | - Translator app written in **Python** using **PySide6**. 34 | - features: 35 | - [x] Support En to Fa and Fa to en 36 | - views: 37 | - ![Translator_fig1](https://user-images.githubusercontent.com/77120507/136650111-d666bc12-aeee-4901-b39b-6a7372107c52.png) 38 | - ![Translator_fig2](https://user-images.githubusercontent.com/77120507/136650114-b88cedfa-d0a8-4695-985f-e969478df27b.png) 39 | -------------------------------------------------------------------------------- /Assignment18/converter/main.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtWidgets import * 2 | from PySide6.QtUiTools import * 3 | from PySide6.QtCore import * 4 | from unit_converter.converter import converts 5 | 6 | class Converter(QMainWindow): 7 | def __init__(self): 8 | super().__init__() 9 | loader = QUiLoader() 10 | self.ui = loader.load('unitConverter.ui', None) 11 | self.ui.show() 12 | 13 | self.ui.convert_btn.clicked.connect(self.convert) 14 | self.ui.convert_comboBox.currentTextChanged.connect(self.on_unitChange) 15 | 16 | def on_unitChange(self): 17 | self.ui.fromUnit_comboBox.clear() 18 | self.ui.toUnit_comboBox.clear() 19 | if self.ui.convert_comboBox.currentText()=='Mass': 20 | self.ui.fromUnit_comboBox.addItems(['g','kg','T','P']) 21 | self.ui.toUnit_comboBox.addItems(['kg','g','T','P']) 22 | elif self.ui.convert_comboBox.currentText()=='Length': 23 | self.ui.fromUnit_comboBox.addItems(['mm','cm','m','km','in']) 24 | self.ui.toUnit_comboBox.addItems(['cm','mm','m','km','in']) 25 | elif self.ui.convert_comboBox.currentText()=='Value': 26 | self.ui.fromUnit_comboBox.addItems(['bit','byte','KByte','MByte','GByte','TByte']) 27 | self.ui.toUnit_comboBox.addItems(['byte','bit','KByte','MByte','GByte','TByte']) 28 | elif self.ui.convert_comboBox.currentText()=='Temperature': 29 | self.ui.fromUnit_comboBox.addItems(['°C','°F','°K']) 30 | self.ui.toUnit_comboBox.addItems(['°F','°C','°K']) 31 | 32 | def convert(self): 33 | quantity = self.ui.input_textBox.text() 34 | current_unit = self.ui.fromUnit_comboBox.currentText() 35 | desired_unit = self.ui.toUnit_comboBox.currentText() 36 | result = converts(quantity=quantity+current_unit, desired_unit=desired_unit) 37 | self.ui.output_textBox.setText(str(round(float(result), 2))) 38 | 39 | app = QApplication([]) 40 | window = Converter() 41 | app.exec() -------------------------------------------------------------------------------- /Assignment07/Translator/main.py: -------------------------------------------------------------------------------- 1 | def readFile(): 2 | try: 3 | myFile = open('translate.txt', 'r') 4 | wordList = myFile.read().split('\n') 5 | for i in range(len(wordList)): 6 | if i%2==0: 7 | tempDic={} 8 | tempDic['english']=wordList[i] 9 | else: 10 | tempDic['persian']=wordList[i] 11 | words.append(tempDic) 12 | myFile.close() 13 | except: 14 | print('We can\'t found translate.txt') 15 | def addNewWord(): 16 | myFile = open('translate.txt', 'a') 17 | eng = input('english: ') 18 | per = input('persian: ') 19 | myFile.write('\n%s\n%s' %(eng, per)) 20 | myFile.close() 21 | words.append({'english':eng, 'persian':per}) 22 | def translater(FROM, TO): 23 | sentenceList = input('Give me sentence: ').split() 24 | translationList=[] 25 | for letter in sentenceList: 26 | dotFlag = False 27 | if letter.find('.')!=-1 and letter.find('.')==len(letter)-1: 28 | letter = letter[:letter.find('.')] 29 | dotFlag = True 30 | tmp = letter 31 | for i in range(len(words)): 32 | if words[i][FROM]==letter: 33 | tmp = words[i][TO] 34 | break 35 | if dotFlag: 36 | translationList.append(tmp+'.') 37 | else: 38 | translationList.append(tmp) 39 | print('Translate: ' + ' '.join(translationList)) 40 | def starterMenu(): 41 | readFile() 42 | while True: 43 | userChoice = int(input('\n1- add new word\n2- translation english2persian\n3- translation persian2english\n4- exit\n')) 44 | if userChoice==1: 45 | addNewWord() 46 | elif userChoice==2: 47 | translater('english', 'persian') 48 | elif userChoice==3: 49 | translater('persian', 'english') 50 | elif userChoice==4: 51 | exit() 52 | else: 53 | print('Are you lost? :)\n') 54 | words = [] 55 | starterMenu() 56 | -------------------------------------------------------------------------------- /Assignment07/Translator/translate.txt: -------------------------------------------------------------------------------- 1 | this 2 | in 3 | is 4 | hast 5 | simple 6 | sade 7 | text 8 | matn 9 | book 10 | ketab 11 | love 12 | doost dashtan 13 | from 14 | az 15 | language 16 | zaban 17 | they 18 | anha 19 | i 20 | man 21 | a 22 | yek 23 | you 24 | shoma 25 | apple 26 | sib 27 | teacher 28 | moalem 29 | class 30 | kelas 31 | mark 32 | nomre 33 | we 34 | ma 35 | computer 36 | rayane 37 | engineer 38 | mohandes 39 | am 40 | hastam 41 | was 42 | bood 43 | programmer 44 | barname nevis 45 | place 46 | makan 47 | what 48 | chi 49 | university 50 | daneshgah 51 | in 52 | dar 53 | go 54 | raftan 55 | sleep 56 | khabidan 57 | were 58 | bodand 59 | he 60 | oo 61 | i.r.iran 62 | jomhooriye eslamiye iran 63 | she 64 | oo 65 | mother 66 | madar 67 | friend 68 | doost 69 | father 70 | pedar 71 | program 72 | barname 73 | hi 74 | salam 75 | hello 76 | salam 77 | word 78 | kalame 79 | god 80 | khoda 81 | school 82 | madrese 83 | clear 84 | tamiz 85 | it 86 | in 87 | team 88 | goroh 89 | tell 90 | goftan 91 | letter 92 | nameh 93 | thank 94 | mamnoon 95 | boy 96 | pesar 97 | girl 98 | dokhtar 99 | farmer 100 | keshavarz 101 | doctor 102 | pezeshk 103 | world 104 | jahan 105 | are 106 | hast 107 | program 108 | barname 109 | new 110 | jadid 111 | mr 112 | aghaye 113 | compute 114 | pardazesh 115 | come 116 | amadan 117 | note 118 | yaddasht 119 | library 120 | ketabkhane 121 | mousqe 122 | masjed 123 | put 124 | gozashtan 125 | theme 126 | poste 127 | celever 128 | bahosh 129 | home 130 | khane 131 | live 132 | zendegi 133 | camera 134 | dorbim 135 | picture 136 | tasvir 137 | use 138 | estefade 139 | good 140 | khob 141 | can 142 | tavanestan 143 | write 144 | neveshtan 145 | problem 146 | moshkel 147 | machine 148 | mashin 149 | result 150 | natije 151 | year 152 | sal 153 | fast 154 | sari 155 | slow 156 | kond 157 | one 158 | yek 159 | two 160 | do 161 | three 162 | se 163 | four 164 | char 165 | five 166 | panj 167 | six 168 | shesh 169 | seven 170 | haft 171 | eight 172 | hasht 173 | ten 174 | dah 175 | job 176 | kar 177 | data 178 | dadeh 179 | network 180 | shabake 181 | could 182 | tavanest 183 | car 184 | mashin 185 | very 186 | besiyar 187 | way 188 | rah 189 | people 190 | mardom 191 | hand 192 | dast 193 | day 194 | rooz 195 | night 196 | shab 197 | all 198 | hame 199 | earth 200 | zamin 201 | down 202 | payin 203 | best 204 | behtarin 205 | for 206 | baraye 207 | row 208 | satr 209 | like 210 | doost dashtan 211 | -------------------------------------------------------------------------------- /Assignment13/platform/enemy.py: -------------------------------------------------------------------------------- 1 | import random 2 | import arcade 3 | class Enemy(arcade.AnimatedWalkingSprite): 4 | def __init__(self): 5 | super().__init__() 6 | self.stand_left_textures = [arcade.load_texture(":resources:images/animated_characters/zombie/zombie_idle.png", mirrored=True)] 7 | self.stand_right_textures = [arcade.load_texture(':resources:images/animated_characters/zombie/zombie_idle.png')] 8 | self.walk_right_textures = [arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk0.png'), 9 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk1.png'), 10 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk2.png'), 11 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk3.png'), 12 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk4.png'), 13 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk5.png'), 14 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk6.png'), 15 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk7.png')] 16 | self.walk_left_textures = [arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk0.png', mirrored=True), 17 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk1.png', mirrored=True), 18 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk2.png', mirrored=True), 19 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk3.png', mirrored=True), 20 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk4.png', mirrored=True), 21 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk5.png', mirrored=True), 22 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk6.png', mirrored=True), 23 | arcade.load_texture(':resources:images/animated_characters/zombie/zombie_walk7.png', mirrored=True)] 24 | self.center_x = random.randint(0,700) 25 | self.center_y = 500 26 | self.speed = 5 27 | self.change_x = random.choice([-1,1]) 28 | self.width=50 29 | self.height=50 -------------------------------------------------------------------------------- /Assignment18/sudoku/Sudoku.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 447 10 | 411 11 | 12 | 13 | 14 | Sudoku Game 15 | 16 | 17 | 18 | icon.pngicon.png 19 | 20 | 21 | 22 | 23 | 24 | 20 25 | 10 26 | 391 27 | 331 28 | 29 | 30 | 31 | 32 | 0 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 2 41 | 42 | 43 | 44 | 45 | New Game 46 | 47 | 48 | 49 | 50 | 51 | 52 | Clear 53 | 54 | 55 | 56 | 57 | 58 | 59 | Check Game 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 0 69 | 70 | 71 | 72 | 73 | 🌑 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 0 86 | 0 87 | 447 88 | 22 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Assignment13/platform/player.py: -------------------------------------------------------------------------------- 1 | import arcade 2 | class Player(arcade.AnimatedWalkingSprite): 3 | def __init__(self): 4 | super().__init__() 5 | self.stand_right_textures =[arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk4.png")] 6 | self.stand_left_textures = [arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk4.png",mirrored = True)] 7 | self.walk_right_textures = [arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk0.png"), 8 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk1.png"), 9 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk2.png"), 10 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk3.png"), 11 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk4.png"), 12 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk5.png"), 13 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk6.png"), 14 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk7.png")] 15 | self.walk_left_textures = [arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk0.png",mirrored = True), 16 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk1.png",mirrored = True), 17 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk2.png",mirrored = True), 18 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk3.png",mirrored = True), 19 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk4.png",mirrored = True), 20 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk5.png",mirrored = True), 21 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk6.png",mirrored = True), 22 | arcade.load_texture(":resources:images/animated_characters/male_adventurer/maleAdventurer_walk7.png",mirrored = True)] 23 | self.center_x = 380 24 | self.center_y = 400 25 | self.speed = 5 26 | self.width = 10 27 | self.height = 15 28 | self.pocket = [] -------------------------------------------------------------------------------- /Assignment01/1_calculator.py: -------------------------------------------------------------------------------- 1 | import math 2 | from sympy import cot 3 | 4 | print('what do you want to do? \n+ - * / radical sin cos tan cot factorial') 5 | tempOperator=input() 6 | if tempOperator=='-': 7 | n1, n2=input('pls give me two values: ').split() 8 | print(round(float(n1)-float(n2), 4)) 9 | elif tempOperator=='+': 10 | n1, n2=input('pls give me two values: ').split() 11 | print(float(n1)+float(n2)) 12 | elif tempOperator=='*': 13 | n1, n2=input('pls give me two values: ').split() 14 | print(round(float(n1)*float(n2),4)) 15 | elif tempOperator=='/': 16 | n1, n2=input('pls give me two values: ').split() 17 | if n2 != '0': 18 | print(round(float(n1)/float(n2),4)) 19 | else: 20 | print('cannot devide by Zero !') 21 | elif tempOperator=='radical': 22 | n1=float(input('pls give me one value: ')) 23 | if n1>=0: 24 | print(math.sqrt(n1)) 25 | else: 26 | print('Invalid Input') 27 | elif tempOperator=='sin': 28 | tempOp=input('degree or radian ? ') 29 | if tempOp=='degree': 30 | n1=float(input('give me a degree: ')) 31 | print(round(math.sin(math.radians(n1)), 4)) 32 | elif tempOp=='radian': 33 | n1=input('give me a radian: e.g. 2 or 0.5 pi: ') 34 | if n1.isnumeric(): 35 | print(round(math.sin(float(n1)), 4)) 36 | else: 37 | n1=n1[:n1.find('pi')].strip() 38 | print(round(math.sin(float(n1)*math.pi), 4)) 39 | elif tempOperator=='cos': 40 | tempOp=input('degree or radian ? ') 41 | if tempOp=='degree': 42 | n1=float(input('give me a degree: ')) 43 | print(round(math.cos(math.radians(n1)), 4)) 44 | elif tempOp=='radian': 45 | n1=input('give me a radian: e.g. 2 or 0.5 pi: ') 46 | if n1.isnumeric(): 47 | print(round(math.cos(float(n1)), 4)) 48 | else: 49 | n1=n1[:n1.find('pi')].strip() 50 | print(round(math.cos(float(n1)*math.pi), 4)) 51 | elif tempOperator=='tan': 52 | tempOp=input('degree or radian ? ') 53 | if tempOp=='degree': 54 | n1=float(input('give me a degree: ')) 55 | print(round(math.tan(math.radians(n1)), 4)) 56 | elif tempOp=='radian': 57 | n1=input('give me a radian: e.g. 2 or 0.5 pi: ') 58 | if n1.isnumeric(): 59 | print(round(math.tan(float(n1)), 4)) 60 | else: 61 | n1=n1[:n1.find('pi')].strip() 62 | print(round(math.tan(float(n1)*math.pi), 4)) 63 | elif tempOperator=='cot': 64 | tempOp=input('degree or radian ? ') 65 | if tempOp=='degree': 66 | n1=float(input('give me a degree: ')) 67 | print(round(cot(math.radians(n1)), 4)) 68 | elif tempOp=='radian': 69 | n1=input('give me a radian: e.g. 2 or 0.5 pi: ') 70 | if n1.isnumeric(): 71 | print(round(cot(float(n1)), 4)) 72 | else: 73 | n1=n1[:n1.find('pi')].strip() 74 | print(round(cot(float(n1)*math.pi), 4)) 75 | elif tempOperator=='factorial': 76 | n1=int(input('pls give me a number: ')) 77 | print(math.factorial(n1)) 78 | -------------------------------------------------------------------------------- /Assignment18/Password generator/passwordGenerator.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 315 10 | 225 11 | 12 | 13 | 14 | Password Generator 15 | 16 | 17 | 18 | key.pngkey.png 19 | 20 | 21 | background-color: rgb(0, 0, 0); 22 | color: rgb(255, 255, 255); 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 0 31 | 0 32 | 33 | 34 | 35 | Qt::AlignCenter 36 | 37 | 38 | 39 | 40 | 41 | 42 | Weak 43 | 44 | 45 | true 46 | 47 | 48 | 49 | 50 | 51 | 52 | Unbreakable 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 18 61 | 62 | 63 | 64 | Password Generator 65 | 66 | 67 | Qt::AlignCenter 68 | 69 | 70 | 71 | 72 | 73 | 74 | Good 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 9 83 | true 84 | 85 | 86 | 87 | background-color: rgb(255, 0, 0); 88 | 89 | 90 | Generate 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /Assignment18/Guess the number/guessTheNumber.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 322 10 | 118 11 | 12 | 13 | 14 | Guess The Number 15 | 16 | 17 | 18 | icon.pngicon.png 19 | 20 | 21 | background-color: rgb(128, 203, 196); 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 10 30 | 31 | 32 | 33 | background-color: rgb(170, 255, 0); 34 | 35 | 36 | Check 37 | 38 | 39 | 40 | 41 | 42 | 43 | Type a number (1-100) 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 10 52 | 53 | 54 | 55 | 56 | background-color: rgb(255, 0, 127); 57 | 58 | 59 | New Game 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 0 68 | 0 69 | 70 | 71 | 72 | 73 | 12 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | Qt::Vertical 82 | 83 | 84 | 85 | 20 86 | 40 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 12 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /Assignment05/2_ticTocToe.py: -------------------------------------------------------------------------------- 1 | from random import randint, choice 2 | from colorama import Fore, Style 3 | from time import time 4 | def draw(): 5 | print() 6 | for row in range(3): 7 | for column in range(3): 8 | if gameBoard[row][column]=='X': 9 | print(Fore.RED + 'X', end=' ') 10 | print(Style.RESET_ALL, end='') 11 | elif gameBoard[row][column]=='O': 12 | print(Fore.CYAN + 'O', end=' ') 13 | print(Style.RESET_ALL, end='') 14 | else: 15 | print('-', end=' ') 16 | print() 17 | def validCordinate(x, y): 18 | if x<=2 and y<=2: 19 | return True 20 | else: 21 | return False 22 | def emptyPosition(x, y): 23 | if gameBoard[x][y]=='-': 24 | return True 25 | else: 26 | return False 27 | def getPosition(name, sign): 28 | while True: 29 | temp = list(map(int, input('\n%s\'s turn.\nrow and column: e.g. 0 2\n' %name).split())) 30 | if validCordinate(temp[0], temp[1]): 31 | if emptyPosition(temp[0], temp[1]): 32 | gameBoard[temp[0]][temp[1]]=sign 33 | return 34 | else: 35 | print('This cordinate is already filled.\n') 36 | else: 37 | print('This cordinate isn\'t valid. try again.\n') 38 | def winCheck(): 39 | for i in range(3): 40 | o, x= 0, 0 41 | for j in range(3): 42 | temp = gameBoard[i][j] 43 | if temp=='X': 44 | x+=1 45 | elif temp=='O': 46 | o+=1 47 | if x==3 or o==3: 48 | return True 49 | for i in range(3): 50 | o, x= 0, 0 51 | for j in range(3): 52 | temp = gameBoard[j][i] 53 | if temp=='X': 54 | x+=1 55 | elif temp=='O': 56 | o+=1 57 | if x==3 or o==3: 58 | return True 59 | if gameBoard[0][0]==gameBoard[1][1]==gameBoard[2][2] and gameBoard[0][0]!='-': 60 | return True 61 | elif gameBoard[0][2]==gameBoard[1][1]==gameBoard[2][0] and gameBoard[0][2]!='-': 62 | return True 63 | return False 64 | def drawCheck(): 65 | for i in range(3): 66 | for j in range(3): 67 | if gameBoard[i][j]=='-': 68 | return False 69 | return True 70 | def stateCheck(): 71 | if winCheck(): 72 | return 'win' 73 | elif drawCheck(): 74 | return 'draw' 75 | else: 76 | return 'nothing' 77 | def endGameFunc(event, name): 78 | if event=='win': 79 | print('\n%s win this round. GG well played.\n' %name) 80 | elif event=='draw': 81 | print('\nDraw.\n') 82 | def playerVsUnknown(who): 83 | player1Sign = choice(['X', "O"]) 84 | player1 = input('player1 name: ') 85 | player2Sign = 'X' if player1Sign=='O' else 'O' 86 | player2 = input('player2 name: ') if who=='human' else 'Eliot-AI' 87 | turn = choice(['X', "O"]) 88 | while True: 89 | turn = player1Sign 90 | draw() 91 | getPosition(player1, turn) 92 | temp = stateCheck() 93 | if temp=='win' or temp=='draw': 94 | endGameFunc(temp, player1) 95 | break 96 | draw() 97 | turn = player2Sign 98 | if who=='human': 99 | getPosition(player2, turn) 100 | else: 101 | while True: 102 | randX = randint(0, 2) 103 | randY = randint(0, 2) 104 | if emptyPosition(randX, randY): 105 | gameBoard[randX][randY]=turn 106 | break 107 | temp = stateCheck() 108 | if temp=='win' or temp=='draw': 109 | endGameFunc(temp, player2) 110 | break 111 | while True: 112 | gameBoard = [['-']*3, ['-']*3, ['-']*3] 113 | playMode = input('\n1.play vs AI\n2.two players\n3.Quit\n') 114 | if playMode=='1' or playMode=='play vs AI': 115 | start = time() 116 | playerVsUnknown('ai') 117 | print(f"Ellapsed time: {round(time() - start, 2)} s") 118 | elif playMode=='2' or playMode=='two players': 119 | start = time() 120 | playerVsUnknown('human') 121 | print(f"Ellapsed time: {round(time() - start, 2)} s") 122 | elif playMode=='3' or playMode=='Quit': 123 | exit() 124 | -------------------------------------------------------------------------------- /Assignment18/Translator En-Fa/translator.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 408 10 | 119 11 | 12 | 13 | 14 | Translator 15 | 16 | 17 | 18 | translator.jpgtranslator.jpg 19 | 20 | 21 | 22 | 23 | 24 | 25 | 6 26 | 27 | 28 | 29 | 30 | 31 | 0 32 | 0 33 | 34 | 35 | 36 | 37 | 10 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | Segoe Print 47 | 10 48 | 49 | 50 | 51 | Translated Text 52 | 53 | 54 | Qt::AlignCenter 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Segoe Print 63 | 10 64 | 65 | 66 | 67 | Text 68 | 69 | 70 | Qt::AlignCenter 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 0 79 | 0 80 | 81 | 82 | 83 | 84 | 10 85 | false 86 | false 87 | 88 | 89 | 90 | 91 | background-color: rgb(251, 140, 0); 92 | 93 | 94 | 95 | En -> Fa 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | Qt::AlignCenter 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 0 114 | 0 115 | 116 | 117 | 118 | 119 | Segoe Script 120 | 11 121 | 122 | 123 | 124 | QPushButton{ 125 | background-color: rgb(251, 140, 0); 126 | } 127 | 128 | 129 | Translate 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /Assignment13/platform/main.py: -------------------------------------------------------------------------------- 1 | import time 2 | import arcade 3 | from player import Player 4 | from enemy import Enemy 5 | from ground import Ground 6 | DEFAULT_FONT_SIZE = 40 7 | class Game(arcade.Window): 8 | def __init__(self): 9 | self.w = 800 10 | self.h = 600 11 | self.gravity = 0.3 12 | self.win = False 13 | super().__init__(self.w , self.h ,"Simple platform game") 14 | self.backeground_image = arcade.load_texture("images/snow.png") 15 | self.time_enterEnemy = time.time() 16 | self.player = Player() 17 | self.ground_list = arcade.SpriteList() 18 | self.enemy_list = arcade.SpriteList() 19 | self.key = arcade.Sprite(":resources:images/items/keyYellow.png") 20 | self.key.center_x=100 21 | self.key.center_y=350 22 | self.key.width = 50 23 | self.key.height=50 24 | self.lock = arcade.Sprite(":resources:images/tiles/lockYellow.png") 25 | self.lock.center_x = 770 26 | self.lock.center_y = 90 27 | self.lock.width = 50 28 | self.lock.height=50 29 | for i in range(0, self.w, 113): 30 | ground = Ground(i ,8) 31 | self.ground_list.append(ground) 32 | for i in range(90,330,113): 33 | ground = Ground(i ,245) 34 | self.ground_list.append(ground) 35 | for i in range(520,650,113): 36 | ground = Ground(i ,190) 37 | self.ground_list.append(ground) 38 | self.physics_engine = arcade.PhysicsEnginePlatformer(self.player,self.ground_list,self.gravity) 39 | self.enemy_physics_engine_list = [] 40 | def on_draw(self): 41 | arcade.start_render() 42 | arcade.draw_lrwh_rectangle_textured(0, 0, self.w, self.h, self.backeground_image) 43 | for ground in self.ground_list: 44 | ground.draw() 45 | self.lock.draw() 46 | if self.win: 47 | arcade.draw_text('YOU WIN', self.w//2-200, self.h//2, arcade.color.BLACK, DEFAULT_FONT_SIZE, width=400, align='center') 48 | arcade.draw_text('Press R for reset game', self.w//2-200, self.h//2-100, arcade.color.BLACK, DEFAULT_FONT_SIZE//2, width=400, align='center') 49 | else: 50 | try: 51 | self.key.draw() 52 | except: 53 | pass 54 | self.player.draw() 55 | for enemy in self.enemy_list: 56 | enemy.draw() 57 | def on_key_press(self, key, modifiers): 58 | if key == arcade.key.LEFT: 59 | self.player.change_x = -1 * self.player.speed 60 | elif key == arcade.key.RIGHT: 61 | self.player.change_x = 1 * self.player.speed 62 | elif key == arcade.key.UP: 63 | if self.physics_engine.can_jump(): 64 | self.player.change_y = 10 65 | elif key == arcade.key.R and self.win: 66 | self.win = False 67 | self.player.pocket.clear() 68 | self.player.center_x = 380 69 | self.player.center_y = 400 70 | self.key = arcade.Sprite(":resources:images/items/keyYellow.png") 71 | self.key.center_x=100 72 | self.key.center_y=350 73 | self.key.width = 50 74 | self.key.height=50 75 | self.lock = arcade.Sprite(":resources:images/tiles/lockYellow.png") 76 | self.lock.center_x = 770 77 | self.lock.center_y = 90 78 | self.lock.width = 50 79 | self.lock.height=50 80 | def on_key_release(self, key, modifiers): 81 | self.player.change_x = 0 82 | def on_update(self, delta_time: float): 83 | self.physics_engine.update() 84 | self.player.update_animation() 85 | for enemy in self.enemy_list: 86 | enemy.update_animation() 87 | for enemy in self.enemy_physics_engine_list: 88 | enemy.update() 89 | self.time_now = time.time() 90 | if self.time_now - self.time_enterEnemy > 5 : 91 | new_enemy = Enemy() 92 | self.enemy_list.append(new_enemy) 93 | self.enemy_physics_engine_list.append(arcade.PhysicsEnginePlatformer(new_enemy,self.ground_list,self.gravity)) 94 | self.time_enterEnemy = time.time() 95 | for enemy in self.enemy_list: 96 | if arcade.check_for_collision(self.player, enemy): 97 | self.key = arcade.Sprite(":resources:images/items/keyYellow.png") 98 | self.key.center_x=100 99 | self.key.center_y=350 100 | self.key.width = 50 101 | self.key.height=50 102 | self.player.pocket.clear() 103 | try: 104 | if arcade.check_for_collision(self.player,self.key): 105 | self.player.pocket.append(self.key) 106 | del self.key 107 | except: 108 | pass 109 | if arcade.check_for_collision(self.player,self.lock) and len(self.player.pocket)==1 : 110 | self.lock.texture = arcade.load_texture(":resources:images/items/flagGreen1.png") 111 | self.lock.width = 60 112 | self.lock.height = 90 113 | self.lock.center_y = 110 114 | self.win = True 115 | if __name__=='__main__': 116 | game = Game() 117 | arcade.run() -------------------------------------------------------------------------------- /Assignment20/to do/todolist.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | To Do List 15 | 16 | 17 | 18 | images/todolisticon.pngimages/todolisticon.png 19 | 20 | 21 | 22 | 23 | 24 | 25 | 0 26 | 27 | 28 | 29 | tasks 30 | 31 | 32 | 33 | 34 | 29 35 | 90 36 | 731 37 | 411 38 | 39 | 40 | 41 | 42 | 2 43 | 44 | 45 | 46 | 47 | QLayout::SetFixedSize 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | ex: Do homework 57 | 58 | 59 | 60 | 61 | 62 | 63 | ex: page 14 to16 64 | 65 | 66 | 67 | 68 | 69 | 70 | ex: 11 july at 20 o'clock 71 | 72 | 73 | 74 | 75 | 76 | 77 | + 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 30 89 | 20 90 | 721 91 | 61 92 | 93 | 94 | 95 | 96 | Roboto Condensed 97 | 33 98 | false 99 | 100 | 101 | 102 | TO DO LIST 103 | 104 | 105 | Qt::AlignCenter 106 | 107 | 108 | 109 | 110 | 111 | complete 112 | 113 | 114 | 115 | 116 | 59 117 | 110 118 | 671 119 | 361 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 60 128 | 20 129 | 671 130 | 81 131 | 132 | 133 | 134 | 135 | Roboto Condensed 136 | 33 137 | 138 | 139 | 140 | Completed Tasks 141 | 142 | 143 | Qt::AlignCenter 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 0 155 | 0 156 | 800 157 | 22 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /Assignment11/snake/main.py: -------------------------------------------------------------------------------- 1 | import random 2 | import arcade 3 | WIN_HEIGHT = 700 4 | WIN_WIDTH = 750 5 | DEFAULT_FONT_SIZE = 5 6 | class Dynamite(arcade.Sprite): 7 | def __init__(self, w, h): 8 | arcade.Sprite.__init__(self) 9 | self.img = 'img/dynamite.png' 10 | self.dynamite = arcade.Sprite(self.img, 0.02) 11 | self.dynamite.center_x = random.randint(10, w-10) 12 | self.dynamite.center_y = random.randint(10, h-10) 13 | def draw(self): 14 | self.dynamite.draw() 15 | class Pear(arcade.Sprite): 16 | def __init__(self, w, h): 17 | arcade.Sprite.__init__(self) 18 | self.img = 'img/pear.png' 19 | self.pear = arcade.Sprite(self.img, 0.1) 20 | self.pear.center_x = random.randint(10, w-10) 21 | self.pear.center_y = random.randint(10, h-10) 22 | def draw(self): 23 | self.pear.draw() 24 | class Apple(arcade.Sprite): 25 | def __init__(self, w, h): 26 | arcade.Sprite.__init__(self) 27 | self.img = 'img/apple.png' 28 | self.apple = arcade.Sprite(self.img, 0.03) 29 | self.apple.center_x = random.randint(10, w-10) 30 | self.apple.center_y = random.randint(10, h-10) 31 | def draw(self): 32 | self.apple.draw() 33 | class Snake(arcade.Sprite): 34 | def __init__(self, w, h): 35 | arcade.Sprite.__init__(self) 36 | self.color_manual = [arcade.color.GREEN, arcade.color.RED, arcade.color.BLACK, arcade.color.CYBER_YELLOW, arcade.color.ORANGE, arcade.color.PINK, arcade.color.BROWN] 37 | self.speed = 4 38 | self.width = 16 39 | self.height = 16 40 | self.center_x = w//2 41 | self.center_y = h//2 42 | self.r = 8 43 | self.change_x = 0 44 | self.change_y = 0 45 | self.score = 1 46 | self.body = [] 47 | self.body.append([self.center_x,self.center_y]) 48 | def draw(self): 49 | for index, item in enumerate(self.body): 50 | arcade.draw_circle_filled(item[0], item[1], self.r, self.color_manual[index%(len(self.color_manual))]) 51 | def move(self): 52 | for i in range(len(self.body)-1, 0, -1): 53 | self.body[i][0] = self.body[i-1][0] 54 | self.body[i][1] = self.body[i-1][1] 55 | self.center_x += self.speed * self.change_x 56 | self.center_y += self.speed * self.change_y 57 | if self.body: 58 | self.body[0][0] += self.speed * self.change_x 59 | self.body[0][1] += self.speed * self.change_y 60 | def eat(self, food): 61 | if food == 'apple': 62 | self.score += 1 63 | self.body.append([self.body[len(self.body)-1][0]+3000, self.body[len(self.body)-1][1]]) 64 | elif food == 'pear': 65 | self.score += 2 66 | self.body.append([self.body[len(self.body)-1][0]+3000, self.body[len(self.body)-1][1]]) 67 | self.body.append([self.body[len(self.body)-1][0]+3000, self.body[len(self.body)-1][1]]) 68 | elif food == 'dynamite': 69 | self.score -= 1 70 | self.body.pop() 71 | class Game(arcade.Window): 72 | def __init__(self): 73 | arcade.Window.__init__(self, WIN_WIDTH, WIN_HEIGHT,"Super Snake by Benyamin Zojaji") 74 | arcade.set_background_color(arcade.color.SAND) 75 | self.snake = Snake(WIN_WIDTH, WIN_HEIGHT) 76 | self.apple = Apple(WIN_WIDTH, WIN_HEIGHT) 77 | self.pear = Pear(WIN_WIDTH, WIN_HEIGHT) 78 | self.dynamite = Dynamite(WIN_WIDTH, WIN_HEIGHT) 79 | def on_draw(self): 80 | arcade.start_render() 81 | self.snake.draw() 82 | self.apple.draw() 83 | self.pear.draw() 84 | self.dynamite.draw() 85 | start_x = 10 86 | start_y = WIN_HEIGHT - 20 87 | arcade.draw_text('Score: %i'%self.snake.score, 88 | start_x, start_y, 89 | arcade.color.BLACK, DEFAULT_FONT_SIZE * 2, width=WIN_WIDTH, align='left') 90 | if self.snake.score <= 0 or self.snake.center_x<0 or self.snake.center_x>WIN_WIDTH or self.snake.center_y<0 or self.snake.center_y>WIN_HEIGHT: 91 | arcade.draw_text('GAME OVER', 92 | WIN_WIDTH//2, WIN_HEIGHT//2, 93 | arcade.color.BLACK, DEFAULT_FONT_SIZE * 5, width=WIN_WIDTH, align='left') 94 | arcade.exit() 95 | def on_update(self, delta_time: float): 96 | self.snake.move() 97 | if arcade.check_for_collision(self.snake, self.apple.apple): 98 | self.snake.eat('apple') 99 | self.apple = Apple(WIN_WIDTH, WIN_HEIGHT) 100 | elif arcade.check_for_collision(self.snake, self.pear.pear): 101 | self.snake.eat('pear') 102 | self.pear = Pear(WIN_WIDTH, WIN_HEIGHT) 103 | elif arcade.check_for_collision(self.snake, self.dynamite.dynamite): 104 | self.snake.eat('dynamite') 105 | self.dynamite = Dynamite(WIN_WIDTH, WIN_HEIGHT) 106 | def on_key_release(self, key, modifiers): 107 | if key == arcade.key.UP: 108 | self.snake.change_x = 0 109 | self.snake.change_y = 1 110 | elif key == arcade.key.DOWN: 111 | self.snake.change_x = 0 112 | self.snake.change_y = -1 113 | elif key == arcade.key.LEFT: 114 | self.snake.change_x = -1 115 | self.snake.change_y = 0 116 | elif key == arcade.key.RIGHT: 117 | self.snake.change_x = 1 118 | self.snake.change_y = 0 119 | if __name__=="__main__": 120 | game = Game() 121 | arcade.run() -------------------------------------------------------------------------------- /Assignment12/main.py: -------------------------------------------------------------------------------- 1 | import math 2 | import random 3 | import time 4 | import arcade 5 | DEFAULT_FONT_SIZE = 40 6 | class Enemy(arcade.Sprite): 7 | def __init__(self, w, h, s=3): 8 | super().__init__(':resources:images/space_shooter/playerShip3_orange.png') 9 | self.speed = s 10 | self.center_x = random.randint(0, w) 11 | self.center_y = h 12 | self.angle = 180 13 | self.width = 50 14 | self.height = 50 15 | def hit(self): 16 | arcade.play_sound(arcade.sound.Sound(':resources:sounds/hit3.wav'), 1.0, 0.0,False) 17 | def move(self): 18 | self.center_y -= self.speed 19 | class Bullet(arcade.Sprite): 20 | def __init__(self, host): 21 | super().__init__(':resources:images/space_shooter/laserRed01.png') 22 | self.speed = 4 23 | self.angle = host.angle 24 | self.center_x = host.center_x 25 | self.center_y = host.center_y 26 | def lunch(self): 27 | arcade.play_sound(arcade.sound.Sound(':resources:sounds/laser4.wav'), 0.2, 0.0,False) 28 | def move(self): 29 | angle_rad = math.radians(self.angle) 30 | self.center_x -= self.speed * math.sin(angle_rad) 31 | self.center_y += self.speed * math.cos(angle_rad) 32 | class Spacecraft(arcade.Sprite): 33 | def __init__(self, w, h): 34 | super().__init__(':resources:images/space_shooter/playerShip1_green.png') 35 | self.width = 48 36 | self.height = 48 37 | self.center_x = w//2 38 | self.center_y = 48 39 | self.change_x = 0 40 | self.change_y = 0 41 | self.angle = 0 42 | self.change_angle = 0 43 | self.bullet_list = [] 44 | self.speed = 4 45 | self.score = 0 46 | self.health = 3 47 | def rotate(self): 48 | self.angle += self.change_angle * self.speed 49 | def move(self): 50 | self.center_x += self.change_x * self.speed 51 | self.center_y += self.change_y * self.speed 52 | def fire(self): 53 | self.bullet_list.append(Bullet(self)) 54 | class Game(arcade.Window): 55 | def __init__(self): 56 | self.w = 800 57 | self.h = 600 58 | super().__init__(self.w, self.h, title="Silver Spacecraft by Benyamin Zojaji") 59 | arcade.set_background_color(arcade.color.BLACK) 60 | self.background_image = arcade.load_texture(':resources:images/backgrounds/stars.png') 61 | self.me = Spacecraft(self.w, self.h) 62 | self.enemy = Enemy(self.w, self.h) 63 | self.next_enemy_time = random.randint(2, 5) 64 | self.enemy_list = [] 65 | self.game_start_time = time.time() 66 | self.start_time = time.time() 67 | self.health_image = arcade.load_texture('img/heart.png') 68 | def on_draw(self): 69 | arcade.start_render() 70 | if self.me.health<=0: 71 | arcade.draw_text('GAME OVER', self.w//2-200, self.h//2, arcade.color.WHITE, DEFAULT_FONT_SIZE //2, width=400, align='center') 72 | else: 73 | arcade.draw_lrwh_rectangle_textured(0, 0, self.w, self.h, self.background_image) 74 | self.me.draw() 75 | for i in range(len(self.me.bullet_list)): 76 | self.me.bullet_list[i].draw() 77 | for i in range(len(self.enemy_list)): 78 | self.enemy_list[i].draw() 79 | for i in range(self.me.health): 80 | arcade.draw_lrwh_rectangle_textured(10+i*35 ,10 ,30 ,30 ,self.health_image) 81 | arcade.draw_text('Score: %i'%self.me.score, self.w-130, 10, arcade.color.WHITE, DEFAULT_FONT_SIZE //2, width=200, align='left') 82 | def on_update(self, delta_time): 83 | self.end_time = time.time() 84 | if self.end_time - self.start_time > self.next_enemy_time: 85 | self.next_enemy_time = random.randint(2, 6) 86 | self.enemy_list.append(Enemy(self.w, self.h, 3+(self.end_time-self.game_start_time)//24)) 87 | self.start_time = time.time() 88 | self.me.rotate() 89 | self.me.move() 90 | for i in range(len(self.me.bullet_list)): 91 | self.me.bullet_list[i].move() 92 | for i in range(len(self.enemy_list)): 93 | self.enemy_list[i].move() 94 | for enemy in self.enemy_list: 95 | for bullet in self.me.bullet_list: 96 | if arcade.check_for_collision(bullet, enemy): 97 | enemy.hit() 98 | self.me.bullet_list.remove(bullet) 99 | self.enemy_list.remove(enemy) 100 | self.me.score += 1 101 | for enemy in self.enemy_list: 102 | if enemy.center_y < 0: 103 | self.me.health -= 1 104 | self.enemy_list.remove(enemy) 105 | for bullet in self.me.bullet_list: 106 | if bullet.center_y>self.height or bullet.center_x<0 or bullet.center_x>self.width: 107 | self.me.bullet_list.remove(bullet) 108 | def on_key_press(self, key, modifiers): 109 | if key == arcade.key.UP: 110 | self.me.change_y = 1 111 | elif key == arcade.key.DOWN: 112 | self.me.change_y = -1 113 | elif key == arcade.key.RIGHT: 114 | self.me.change_x = 1 115 | elif key == arcade.key.LEFT: 116 | self.me.change_x = -1 117 | elif key == arcade.key.C: 118 | self.me.change_angle = 1 119 | elif key == arcade.key.V: 120 | self.me.change_angle = -1 121 | elif key == arcade.key.SPACE: 122 | self.me.fire() 123 | self.me.bullet_list[-1].lunch() 124 | def on_key_release(self, key, modifiers): 125 | self.me.change_angle = 0 126 | self.me.change_x = 0 127 | self.me.change_y = 0 128 | if __name__ == '__main__': 129 | Game() 130 | arcade.run() 131 | -------------------------------------------------------------------------------- /Assignment20/AI Snake/main.py: -------------------------------------------------------------------------------- 1 | import random 2 | import arcade 3 | 4 | WIN_HEIGHT = 700 5 | WIN_WIDTH = 750 6 | DEFAULT_FONT_SIZE = 5 7 | 8 | 9 | class Dynamite(arcade.Sprite): 10 | def __init__(self, w, h): 11 | arcade.Sprite.__init__(self) 12 | self.img = 'img/dynamite.png' 13 | self.dynamite = arcade.Sprite(self.img, 0.02) 14 | self.dynamite.center_x = random.randint(10, w - 10) 15 | self.dynamite.center_y = random.randint(10, h - 10) 16 | 17 | def draw(self): 18 | self.dynamite.draw() 19 | 20 | 21 | class Pear(arcade.Sprite): 22 | def __init__(self, w, h): 23 | arcade.Sprite.__init__(self) 24 | self.img = 'img/pear.png' 25 | self.pear = arcade.Sprite(self.img, 0.1) 26 | self.pear.center_x = random.randint(10, w - 10) 27 | self.pear.center_y = random.randint(10, h - 10) 28 | 29 | def draw(self): 30 | self.pear.draw() 31 | 32 | 33 | class Apple(arcade.Sprite): 34 | def __init__(self, w, h): 35 | arcade.Sprite.__init__(self) 36 | self.img = 'img/apple.png' 37 | self.apple = arcade.Sprite(self.img, 0.03) 38 | self.apple.center_x = random.randint(10, w - 10) 39 | self.apple.center_y = random.randint(10, h - 10) 40 | 41 | def draw(self): 42 | self.apple.draw() 43 | 44 | 45 | class Snake(arcade.Sprite): 46 | def __init__(self, w, h): 47 | arcade.Sprite.__init__(self) 48 | self.color_manual = [arcade.color.GREEN, arcade.color.RED, arcade.color.BLACK, arcade.color.CYBER_YELLOW, 49 | arcade.color.ORANGE, arcade.color.PINK, arcade.color.BROWN] 50 | self.speed = 1 51 | self.width = 16 52 | self.height = 16 53 | self.center_x = w // 2 54 | self.center_y = h // 2 55 | self.r = 8 56 | self.change_x = 0 57 | self.change_y = 0 58 | self.score = 1 59 | self.body = [] 60 | self.body.append([self.center_x, self.center_y]) 61 | 62 | def draw(self): 63 | for index, item in enumerate(self.body): 64 | arcade.draw_circle_filled(item[0], item[1], self.r, self.color_manual[index % (len(self.color_manual))]) 65 | 66 | def move(self): 67 | for i in range(len(self.body) - 1, 0, -1): 68 | self.body[i][0] = self.body[i - 1][0] 69 | self.body[i][1] = self.body[i - 1][1] 70 | self.center_x += self.speed * self.change_x 71 | self.center_y += self.speed * self.change_y 72 | if self.body: 73 | self.body[0][0] += self.speed * self.change_x 74 | self.body[0][1] += self.speed * self.change_y 75 | 76 | def eat(self, food): 77 | if food == 'apple': 78 | self.score += 1 79 | self.body.append([self.body[len(self.body) - 1][0] + 3000, self.body[len(self.body) - 1][1]]) 80 | elif food == 'pear': 81 | self.score += 2 82 | self.body.append([self.body[len(self.body) - 1][0] + 3000, self.body[len(self.body) - 1][1]]) 83 | self.body.append([self.body[len(self.body) - 1][0] + 3000, self.body[len(self.body) - 1][1]]) 84 | elif food == 'dynamite': 85 | self.score -= 1 86 | self.body.pop() 87 | 88 | 89 | class Game(arcade.Window): 90 | def __init__(self): 91 | arcade.Window.__init__(self, WIN_WIDTH, WIN_HEIGHT, "Clever Snake by Benyamin Zojaji") 92 | arcade.set_background_color(arcade.color.SAND) 93 | self.snake = Snake(WIN_WIDTH, WIN_HEIGHT) 94 | self.apple = Apple(WIN_WIDTH, WIN_HEIGHT) 95 | self.pear = Pear(WIN_WIDTH, WIN_HEIGHT) 96 | self.dynamite = Dynamite(WIN_WIDTH, WIN_HEIGHT) 97 | 98 | def on_draw(self): 99 | arcade.start_render() 100 | self.snake.draw() 101 | self.apple.draw() 102 | self.pear.draw() 103 | self.dynamite.draw() 104 | start_x = 10 105 | start_y = WIN_HEIGHT - 20 106 | arcade.draw_text('Score: %i' % self.snake.score, 107 | start_x, start_y, 108 | arcade.color.BLACK, DEFAULT_FONT_SIZE * 2, width=WIN_WIDTH, align='left') 109 | if self.snake.score <= 0 or self.snake.center_x < 0 or self.snake.center_x > WIN_WIDTH or self.snake.center_y < 0 or self.snake.center_y > WIN_HEIGHT: 110 | arcade.draw_text('GAME OVER', 111 | WIN_WIDTH // 2, WIN_HEIGHT // 2, 112 | arcade.color.BLACK, DEFAULT_FONT_SIZE * 5, width=WIN_WIDTH, align='left') 113 | arcade.exit() 114 | 115 | def on_update(self, delta_time: float): 116 | if self.snake.center_x < self.apple.apple.center_x: 117 | self.snake.change_x = 1 118 | elif self.snake.center_x > self.apple.apple.center_x: 119 | self.snake.change_x = -1 120 | else: 121 | self.snake.change_x = 0 122 | if self.snake.center_y < self.apple.apple.center_y: 123 | self.snake.change_y = 1 124 | elif self.snake.center_y > self.apple.apple.center_y: 125 | self.snake.change_y = -1 126 | else: 127 | self.snake.change_y = 0 128 | self.snake.move() 129 | if arcade.check_for_collision(self.snake, self.apple.apple): 130 | self.snake.eat('apple') 131 | self.apple = Apple(WIN_WIDTH, WIN_HEIGHT) 132 | elif arcade.check_for_collision(self.snake, self.pear.pear): 133 | self.snake.eat('pear') 134 | self.pear = Pear(WIN_WIDTH, WIN_HEIGHT) 135 | elif arcade.check_for_collision(self.snake, self.dynamite.dynamite): 136 | self.snake.eat('dynamite') 137 | self.dynamite = Dynamite(WIN_WIDTH, WIN_HEIGHT) 138 | 139 | 140 | 141 | if __name__ == "__main__": 142 | game = Game() 143 | arcade.run() -------------------------------------------------------------------------------- /Assignment17/main.py: -------------------------------------------------------------------------------- 1 | from random import choice, randint 2 | from functools import partial 3 | from PySide6.QtWidgets import * 4 | from PySide6.QtUiTools import * 5 | from PySide6.QtCore import * 6 | 7 | 8 | class Window(QMainWindow): 9 | def __init__(self): 10 | super().__init__() 11 | loader = QUiLoader() 12 | self.ui = loader.load('form.ui', None) 13 | self.ui.show() 14 | 15 | self.AI = False 16 | 17 | self.x_score = 0 18 | self.o_score = 0 19 | self.scoreBoardUpdate() 20 | 21 | self.game = [[self.ui.btn_0, self.ui.btn_1, self.ui.btn_2], [self.ui.btn_3, self.ui.btn_4, self.ui.btn_5], 22 | [self.ui.btn_6, self.ui.btn_7, self.ui.btn_8]] 23 | 24 | for i in range(3): 25 | for j in range(3): 26 | self.game[i][j].setText('') 27 | self.game[i][j].setStyleSheet('background-color: skyblue') 28 | self.game[i][j].clicked.connect(partial(self.play, i, j)) 29 | self.ui.about_btn.clicked.connect(self.about) 30 | self.ui.newGame_btn.clicked.connect(partial(self.newGame)) 31 | self.turn = choice(['X', 'O']) 32 | self.ui.rd_btn2.setChecked(True) 33 | 34 | def about(self): 35 | msgBox = QMessageBox() 36 | msgBox.setText('Programmer: Benyamin Zojaji\nEmail: benyamin.zojaji@icloud.com\nMade with ❤') 37 | msgBox.exec() 38 | 39 | def scoreBoardUpdate(self): 40 | self.ui.scoreboard.setText(str(self.x_score) + ' - ' + str(self.o_score)) 41 | 42 | def play(self, i, j): 43 | if self.ui.rd_btn1.isChecked(): 44 | self.AI = True 45 | elif self.ui.rd_btn2.isChecked(): 46 | self.AI = False 47 | 48 | if self.game[i][j].text() == '': 49 | self.set_position(i, j) 50 | self.check() 51 | if self.AI: 52 | x, y = self.get_position() 53 | self.set_position(x, y) 54 | self.check() 55 | 56 | else: 57 | msgBox = QMessageBox() 58 | msgBox.setText('You can\'t select this position. ˘︹˘ ') 59 | msgBox.exec() 60 | 61 | def set_position(self, i, j): 62 | if self.turn == 'X': 63 | self.turn = 'O' 64 | self.game[i][j].setText('X') 65 | self.game[i][j].setStyleSheet('color: green; background-color: lightgreen') 66 | else: 67 | self.turn = 'X' 68 | self.game[i][j].setText('O') 69 | self.game[i][j].setStyleSheet('color: red; background-color: pink') 70 | 71 | def get_position(self): 72 | while True: 73 | x = randint(0, 2) 74 | y = randint(0, 2) 75 | if self.game[x][y].text() == '': 76 | break 77 | return x, y 78 | 79 | def check(self): 80 | state = self.winCheck() 81 | if state == 'X': 82 | msgBox = QMessageBox() 83 | msgBox.setText('X wins.') 84 | msgBox.exec() 85 | self.x_score += 1 86 | self.scoreBoardUpdate() 87 | self.newGame(False) 88 | elif state == 'O': 89 | msgBox = QMessageBox() 90 | msgBox.setText('O wins.') 91 | msgBox.exec() 92 | self.o_score += 1 93 | self.scoreBoardUpdate() 94 | self.newGame(False) 95 | elif state == 'draw': 96 | msgBox = QMessageBox() 97 | msgBox.setText('draw.') 98 | msgBox.exec() 99 | self.newGame(False) 100 | 101 | def winCheck(self): 102 | # win check 103 | for i in range(3): 104 | o, x = 0, 0 105 | for j in range(3): 106 | temp = self.game[i][j].text() 107 | if temp == 'X': 108 | x += 1 109 | elif temp == 'O': 110 | o += 1 111 | if x == 3: 112 | return 'X' 113 | elif o == 3: 114 | return 'O' 115 | for i in range(3): 116 | o, x = 0, 0 117 | for j in range(3): 118 | temp = self.game[j][i].text() 119 | if temp == 'X': 120 | x += 1 121 | elif temp == 'O': 122 | o += 1 123 | if x == 3: 124 | return 'X' 125 | elif o == 3: 126 | return 'O' 127 | if self.game[0][0].text() == self.game[1][1].text() == self.game[2][2].text() and self.game[0][0].text() == 'X': 128 | return 'X' 129 | elif self.game[0][0].text() == self.game[1][1].text() == self.game[2][2].text() and self.game[0][ 130 | 0].text() == 'O': 131 | return 'O' 132 | elif self.game[0][2].text() == self.game[1][1].text() == self.game[2][0].text() and self.game[0][ 133 | 2].text() == 'O': 134 | return 'O' 135 | elif self.game[0][2].text() == self.game[1][1].text() == self.game[2][0].text() and self.game[0][ 136 | 2].text() == 'X': 137 | return 'X' 138 | # draw and continue check 139 | for i in range(3): 140 | for j in range(3): 141 | if self.game[i][j].text() == '': 142 | return 'continue' 143 | return 'draw' 144 | 145 | def newGame(self, score_reset=True): 146 | for i in range(3): 147 | for j in range(3): 148 | self.game[i][j].setText('') 149 | self.game[i][j].setStyleSheet('color: black; background-color: skyblue') 150 | self.turn = choice(['X', 'O']) 151 | if score_reset: 152 | self.x_score = 0 153 | self.o_score = 0 154 | self.scoreBoardUpdate() 155 | 156 | 157 | app = QApplication([]) 158 | window = Window() 159 | app.exec() 160 | -------------------------------------------------------------------------------- /Assignment18/sudoku/main.py: -------------------------------------------------------------------------------- 1 | from functools import partial 2 | from random import randint 3 | from PySide6.QtWidgets import * 4 | from PySide6.QtUiTools import * 5 | from PySide6.QtCore import * 6 | 7 | 8 | class Sudoku(QMainWindow): 9 | def __init__(self): 10 | super().__init__() 11 | loader = QUiLoader() 12 | self.ui = loader.load('sudoku.ui', None) 13 | 14 | self.file_path = '' 15 | 16 | self.game = [[None for i in range(9)] for j in range(9)] 17 | 18 | for i in range(9): 19 | for j in range(9): 20 | tb = QLineEdit() 21 | tb.setStyleSheet('font-size: 12px') 22 | tb.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) 23 | tb.setAlignment(Qt.AlignCenter) # set Alignment 24 | self.game[i][j] = tb # back-end 25 | self.game[i][j].textChanged.connect(self.checkGame) # connect textBoxes to check method 26 | self.ui.my_grid.addWidget(tb, i, j) # front-end 27 | 28 | self.ui.show() 29 | self.ui.newgame_btn.clicked.connect(partial(self.setGame, True)) 30 | self.ui.clear_btn.clicked.connect(partial(self.setGame, False)) 31 | self.ui.check_btn.clicked.connect(self.checkGame) 32 | self.ui.dark_btn.clicked.connect(self.dark) 33 | 34 | 35 | def dark(self): 36 | if self.ui.dark_btn.text()=='🌑': 37 | self.ui.dark_btn.setText('🌕') 38 | self.ui.setStyleSheet('background-color: rgb(161, 161, 161)') 39 | else: 40 | self.ui.dark_btn.setText('🌑') 41 | self.ui.setStyleSheet('') 42 | 43 | def checkGame(self): 44 | flag= True 45 | # check rows 46 | for row in range(9): 47 | for i in range(9): 48 | for j in range(9): 49 | if self.game[row][i].text()==self.game[row][j].text() and i!=j and self.game[row][i].text()!='': 50 | self.game[row][j].setStyleSheet('font-size: 12; background-color: pink;') 51 | flag=False 52 | # check columns 53 | for col in range(9): 54 | for i in range(9): 55 | for j in range(9): 56 | if self.game[i][col].text()==self.game[j][col].text() and i!=j and self.game[i][col].text()!='': 57 | self.game[i][col].setStyleSheet('font-size: 12; background-color: pink;') 58 | flag=False 59 | # check cel 60 | cel1=[] 61 | for i in range(0, 3): 62 | for j in range(0, 3): 63 | cel1.append(self.game[i][j].text()) 64 | cel2=[] 65 | for i in range(0, 3): 66 | for j in range(3, 6): 67 | cel2.append(self.game[i][j].text()) 68 | cel3=[] 69 | for i in range(0, 3): 70 | for j in range(6, 9): 71 | cel3.append(self.game[i][j].text()) 72 | cel4=[] 73 | for i in range(3, 6): 74 | for j in range(0, 3): 75 | cel4.append(self.game[i][j].text()) 76 | cel5=[] 77 | for i in range(3, 6): 78 | for j in range(3, 6): 79 | cel5.append(self.game[i][j].text()) 80 | cel6=[] 81 | for i in range(3, 6): 82 | for j in range(6, 9): 83 | cel6.append(self.game[i][j].text()) 84 | cel7=[] 85 | for i in range(6, 9): 86 | for j in range(0, 3): 87 | cel7.append(self.game[i][j].text()) 88 | cel8=[] 89 | for i in range(6, 9): 90 | for j in range(3, 6): 91 | cel8.append(self.game[i][j].text()) 92 | cel9=[] 93 | for i in range(6, 9): 94 | for j in range(6, 9): 95 | cel9.append(self.game[i][j].text()) 96 | all_cel = [cel1,cel2,cel3,cel4,cel5,cel6,cel7,cel8,cel9] 97 | for i in range(9): # allcel count 98 | for j in range(9): # cell count 99 | for z in range(9): 100 | if all_cel[i][j]==all_cel[i][z] and j!=z and all_cel[i][j]!='': 101 | self.game[(int(i/3))*3+int(z/3)][(int(i%3))*3+(z%3)].setStyleSheet('font-size: 12; background-color: pink;') 102 | flag=False 103 | 104 | for i in range(9): # check empty 105 | for j in range(9): 106 | if all_cel[i][j]=='': 107 | flag=False 108 | if flag: 109 | msgBox = QMessageBox() 110 | msgBox.setText('Hooray! You did it! press New Game. ^^') 111 | msgBox.exec() 112 | 113 | def setGame(self, newGame= False): 114 | for i in range(9): 115 | for j in range(9): 116 | self.game[i][j].setText('') 117 | 118 | try: 119 | if newGame==True: 120 | r = randint(1, 6) 121 | self.file_path = f'data/s{r}.txt' 122 | f = open(self.file_path, 'r') 123 | big_text = f.read() 124 | rows = big_text.split('\n') 125 | 126 | for i in range(9): 127 | numbers = rows[i].split(' ') 128 | for j in range(9): 129 | if numbers[j] != '0': 130 | self.game[i][j].setStyleSheet('font-size: 12px; color: black') 131 | self.game[i][j].setText(numbers[j]) 132 | self.game[i][j].setReadOnly(True) # read only for main self.board numbers 133 | else: 134 | self.game[i][j].setStyleSheet('font-size: 12px; color: green') 135 | self.game[i][j].setReadOnly(False) 136 | except: 137 | msgBox = QMessageBox() 138 | msgBox.setText('Error: data file missing.') 139 | msgBox.exec() 140 | 141 | app = QApplication([]) 142 | window = Sudoku() 143 | app.exec() -------------------------------------------------------------------------------- /Assignment06/store/main.py: -------------------------------------------------------------------------------- 1 | from colorama import Fore, Back, Style 2 | from time import sleep 3 | import cowsay 4 | import pyqrcode 5 | import png 6 | #from pyqrcode import QRCode 7 | def refreshData(): 8 | myFile = open('database.txt', 'r') 9 | data = myFile.read() 10 | dataLine = data.split('\n') 11 | for piece in dataLine: 12 | productDict = {} 13 | if not piece: 14 | break 15 | piece = piece.split(',') 16 | productDict['code'] = piece[0] 17 | productDict['name'] = piece[1] 18 | productDict['price'] = int(piece[2]) 19 | productDict['count'] = int(piece[3]) 20 | PRODUCTs[piece[0]] = productDict 21 | myFile.close() 22 | def showProducts(): 23 | sleep(0.5) 24 | print('\ncode\tname\t\tprice\tcount\n') 25 | sleep(0.5) 26 | for key, value in PRODUCTs.items(): 27 | print('%s\t%s\t\t%i\t%i' %(key, value['name'], int(value['price']), int(value['count']))) 28 | print() 29 | def load(): 30 | print(Fore.LIGHTYELLOW_EX, end='') 31 | cowsay.cow('Bni Store') 32 | print(Style.RESET_ALL, end='') 33 | refreshData() 34 | def buy(): 35 | cartDic = {} 36 | while True: 37 | print('\nHint:You can discard with type \'d\' \n') 38 | code = input('code: ') 39 | if code in PRODUCTs.keys(): 40 | while True: 41 | vlu = input('How much: ') 42 | if vlu=='d': 43 | break 44 | elif 0RANDOM_NUMBER: 33 | msg = bot.send_message(m.chat.id, 'lower', reply_markup=markup) 34 | bot.register_next_step_handler(msg, gm1) 35 | elif int(m.text)==RANDOM_NUMBER: 36 | msg = bot.send_message(m.chat.id, 'Thats right. ^^', reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 37 | except ValueError: 38 | bot.send_message(m.chat.id, 'something is wrong with your input. give me a number 😢', reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 39 | except: 40 | bot.send_message(m.chat.id, 'something is wrong. Call my dad 😭\n@mrbni Error code:gm1', reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 41 | else: 42 | bot.reply_to(m, 'I expect a number not a command. 🤔') 43 | bot.send_message(m.chat.id, 'now tell me your command.') 44 | @bot.message_handler(commands=['age']) 45 | def age_func(m): 46 | msg = bot.send_message(m.chat.id, 'Just give me your date of birth ^^ e.g. 1360/4/12') 47 | bot.register_next_step_handler(msg, age1) 48 | def age1(m): 49 | if not m.text.startswith('/'): 50 | userBirth = m.text.split('/') 51 | if len(userBirth)==3: 52 | difference = JalaliDatetime.now() - JalaliDatetime(userBirth[0], userBirth[1], userBirth[2]) 53 | bot.send_message(m.chat.id, 'You are about '+ str(difference.days//365)) 54 | else: 55 | bot.reply_to(m, 'something is wrong with your input.') 56 | else: 57 | bot.reply_to(m, 'I expect your date of birth not a command. 🤔') 58 | bot.send_message(m.chat.id, 'now tell me your command.') 59 | @bot.message_handler(commands=['voice']) 60 | def voice_func(m): 61 | msg = bot.send_message(m.chat.id, 'Just give me your text ^^ e.g. Hey there') 62 | bot.register_next_step_handler(msg, vc1) 63 | def vc1(m): 64 | if not m.text.startswith('/'): 65 | try: 66 | vc = gTTS(text=m.text, slow=False) 67 | vc.save('voice.ogg') 68 | voice = open('voice.ogg', 'rb') 69 | bot.send_voice(m.chat.id, voice) 70 | except: 71 | bot.send_message(m.chat.id, 'something is wrong. Call my dad 😭\n@mrbni Error code:vc1') 72 | else: 73 | bot.reply_to(m, 'I expect text not a command. 🤔') 74 | bot.send_message(m.chat.id, 'now tell me your command.') 75 | @bot.message_handler(commands=['max']) 76 | def max_func(m): 77 | msg = bot.send_message(m.chat.id, 'Just give me your numbers seprated with , ^^ e.g. 3,5,10,2,15,4') 78 | bot.register_next_step_handler(msg, mx1) 79 | def mx1(m): 80 | if not m.text.startswith('/'): 81 | try: 82 | numbers = list(map(int, m.text.split(','))) 83 | bot.send_message(m.chat.id, 'biggest number: '+str(max(numbers))) 84 | except ValueError: 85 | bot.reply_to(m, 'Is that a number??😶') 86 | except: 87 | bot.send_message(m.chat.id, 'something is wrong. Call my dad 😭\n@mrbni Error code:mx1') 88 | else: 89 | bot.reply_to(m, 'I expect numbers not a command. 🤔') 90 | bot.send_message(m.chat.id, 'now tell me your command.') 91 | @bot.message_handler(commands=['argmax']) 92 | def argmax_welcome(m): 93 | msg = bot.send_message(m.chat.id, 'Just give me your numbers seprated with , ^^ e.g. 3,5,10,2,15,4') 94 | bot.register_next_step_handler(msg, agmx1) 95 | def agmx1(m): 96 | if not m.text.startswith('/'): 97 | try: 98 | numbers = list(map(int, m.text.split(','))) 99 | bot.send_message(m.chat.id, 'biggest number index: '+str(numbers.index(max(numbers)))) 100 | except ValueError: 101 | bot.reply_to(m, 'Is that a number??😶') 102 | except: 103 | bot.send_message(m.chat.id, 'something is wrong. Call my dad 😭\n@mrbni Error code:agmx1') 104 | else: 105 | bot.reply_to(m, 'I expect numbers not a command. 🤔') 106 | bot.send_message(m.chat.id, 'now tell me your command.') 107 | @bot.message_handler(commands=['qrcode']) 108 | def qrcode_func(m): 109 | msg = bot.send_message(m.chat.id, 'Just give me your text/url/... , ^^ e.g. https://t.me/mrbni') 110 | bot.register_next_step_handler(msg, qr1) 111 | def qr1(m): 112 | if not m.text.startswith('/'): 113 | try: 114 | img = qrcode.make(m.text) 115 | img.save('QRCODE.png') 116 | photo = open('QRCODE.png', 'rb') 117 | bot.send_photo(m.chat.id, photo) 118 | except: 119 | bot.send_message(m.chat.id, 'something is wrong. Call my dad 😭\n@mrbni Error code:qr1') 120 | else: 121 | bot.reply_to(m, 'I expect numbers not a command. 🤔') 122 | bot.send_message(m.chat.id, 'now tell me your command.') 123 | @bot.message_handler(commands=['help']) 124 | def help_func(message): 125 | bot.reply_to(message, 'For any issues pls contact my creator.\nbenyamin.zojaji@gmail.com\n/game -guess the number game 🎮\n/age -calculate your age 🧍\n/voice -convert text to voice 🎼\n/max -find biggest number ✔️\n/argmax -find index of biggest number ☑️\n/qrcode -make Qrcode 🧷\n/help -show commands ℹ️') 126 | bot.polling(none_stop=True) -------------------------------------------------------------------------------- /Assignment10-Mini Project/main.py: -------------------------------------------------------------------------------- 1 | import film, series, documentary, clip 2 | import csv 3 | class Main: 4 | def __init__(self): 5 | print('Hello there! just a second for loading Data!') 6 | self.totalMedia = [] 7 | with open('db.csv') as f: 8 | reader = csv.reader(f) 9 | for data in reader: 10 | if not data: 11 | break 12 | if data[0]=='film': 13 | self.totalMedia.append(film.Film(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7])) 14 | elif data[0]=='series': 15 | self.totalMedia.append(series.Series(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8],data[9])) 16 | elif data[0]=='clip': 17 | self.totalMedia.append(clip.Clip(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7])) 18 | elif data[0]=='documentary': 19 | self.totalMedia.append(documentary.Documentary(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8])) 20 | print('Data loaded!') 21 | self.menu() 22 | def menu(self): 23 | choose = input('1- Add\n2- Edit\n3- Delete\n4- show all medias\n5- Download\n6- Search by name\n7- search by duration\n8- QrCode\n9- save changes and Exit\n') 24 | if choose=='1': 25 | self.add() 26 | elif choose=='2': 27 | self.edit() 28 | elif choose=='3': 29 | self.delete() 30 | elif choose=='4': 31 | self.showAllMedias() 32 | elif choose=='5': 33 | self.download() 34 | elif choose=='6': 35 | self.searchWithName() 36 | elif choose=='7': 37 | self.searchWithDuration() 38 | elif choose=='8': 39 | self.qrcode() 40 | elif choose=='9': 41 | self.saveExit() 42 | def add(self): 43 | data = [] 44 | data.append(input('film/series/documentary/clip: ')) 45 | data.append(input('Name: ')) 46 | data.append(input('Director: ')) 47 | data.append(input('Imdb: ')) 48 | data.append(input('Url: ')) 49 | data.append(input('Duration: ')) 50 | data.append(input('Casts: ')) 51 | if data[0]=='film': 52 | data.append(input('Genre: ')) 53 | self.totalMedia.append(film.Film(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7])) 54 | elif data[0]=='series': 55 | data.append(input('Season: ')) 56 | data.append(input('Episode: ')) 57 | data.append(input('Genre: ')) 58 | self.totalMedia.append(series.Series(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8],data[9])) 59 | elif data[0]=='clip': 60 | data.append(input('Subject: ')) 61 | self.totalMedia.append(clip.Clip(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7])) 62 | elif data[0]=='documentary': 63 | data.append(input('Time Spend: ')) 64 | data.append(input('Subject: ')) 65 | self.totalMedia.append(documentary.Documentary(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8])) 66 | else: 67 | print('we don\'t support %s format'%data[0]) 68 | self.menu() 69 | def edit(self): 70 | NAME = input('name: ') 71 | for data in self.totalMedia: 72 | if data.name == NAME: 73 | data.edit() 74 | print('Done.') 75 | self.menu() 76 | print('There is no media with that name.') 77 | self.menu() 78 | def delete(self): 79 | NAME = input('name: ') 80 | for data in self.totalMedia: 81 | if data.name == NAME: 82 | self.totalMedia.remove(data) 83 | print('Deleted.') 84 | self.menu() 85 | print('There is no media with that name.') 86 | self.menu() 87 | def showAllMedias(self): 88 | for piece in self.totalMedia: 89 | piece.showInfo() 90 | self.menu() 91 | def download(self): 92 | NAME = input('name: ') 93 | for data in self.totalMedia: 94 | if data.name == NAME: 95 | data.download() 96 | print('Downloaded.') 97 | self.menu() 98 | print('There is no media with that name.') 99 | self.menu() 100 | def searchWithName(self): 101 | NAME = input('name: ') 102 | for data in self.totalMedia: 103 | if data.name == NAME: 104 | print('FOUND.') 105 | self.menu() 106 | print('NOT FOUND.') 107 | self.menu() 108 | def searchWithDuration(self): 109 | time = list(map(int, input('give me 2 times i will found films between it. e.g. 70 90 ').split())) 110 | cnt = 0 111 | for data in self.totalMedia: 112 | if data.category=='film' and time[0]<=int(data.duration)<=time[1]: 113 | print('%i. %s'%(cnt, data.name)) 114 | cnt+=1 115 | if cnt==0: 116 | print('sorry we don\'t have a film with your desire duration.') 117 | else: 118 | print('we only found %i film(s).'%cnt) 119 | self.menu() 120 | def qrcode(self): 121 | NAME = input('name: ') 122 | for data in self.totalMedia: 123 | if data.name == NAME: 124 | data.qrcode() 125 | print('QRcode created!') 126 | self.menu() 127 | print('There is no such a media with that name!') 128 | self.menu() 129 | def saveExit(self): 130 | with open('db.csv' , 'w' ,newline='') as f: 131 | writer = csv.writer(f) 132 | for data in self.totalMedia: 133 | if data.category=='film': 134 | writer.writerow([data.category,data.name,data.director,data.imdbScore,data.url,data.duration,data.get_casts(),data.genre]) 135 | elif data.category=='series': 136 | writer.writerow([data.category,data.name,data.director,data.imdbScore,data.url,data.duration,data.get_casts(),data.season,data.episode,data.genre]) 137 | elif data.category=='clip': 138 | writer.writerow([data.category,data.name,data.director,data.imdbScore,data.url,data.duration,data.get_casts(),data.subject]) 139 | elif data.category=='documentary': 140 | writer.writerow([data.category,data.name,data.director,data.imdbScore,data.url,data.duration,data.get_casts(),data.timeSpend,data.subject]) 141 | exit() 142 | if __name__ == "__main__": 143 | Main() 144 | -------------------------------------------------------------------------------- /Assignment20/to do/main.py: -------------------------------------------------------------------------------- 1 | from PySide6.QtWidgets import * 2 | from PySide6.QtUiTools import * 3 | from PySide6.QtCore import * 4 | from PySide6.QtGui import * 5 | import database 6 | 7 | class Popup(QWindow): 8 | def __init__(self, id): 9 | super().__init__() 10 | loader = QUiLoader() 11 | self.ui = loader.load('popup.ui', None) 12 | self.ui.show() 13 | 14 | # get and assign data to labels 15 | details = database.get_detail(id) 16 | self.ui.id_label.setText(f'{details[0][0]}') 17 | self.ui.title_label.setText(f'{details[0][1]}') 18 | self.ui.description_label.setText(f'{details[0][2]}') 19 | self.ui.time_label.setText(f'{details[0][3]}') 20 | if details[0][4]==1: 21 | self.ui.done_label.setText('YES') 22 | else: 23 | self.ui.done_label.setText('NO') 24 | 25 | self.ui.back_btn.clicked.connect(self.back) 26 | 27 | def back(self): 28 | self.ui = MainWindow() 29 | 30 | 31 | class MainWindow(QMainWindow): 32 | def __init__(self): 33 | super().__init__() 34 | loader = QUiLoader() 35 | self.ui = loader.load('todolist.ui', None) 36 | self.ui.show() 37 | 38 | self.lastID = 0 39 | 40 | self.readFromDataBase() 41 | 42 | self.ui.add_btn.clicked.connect(self.addNewTaskToDataBase) 43 | self.ui.tabWidget.currentChanged.connect(self.tabChange) 44 | 45 | def clearUI_complete(self): 46 | #print(f'objects{self.ui.gridLayout_comp.count()}') 47 | for i in reversed(range(self.ui.gridLayout_comp.count())): 48 | self.ui.gridLayout_comp.itemAt(i).widget().deleteLater() 49 | 50 | def tabChange(self): 51 | self.clearUI_complete() 52 | # complete 53 | result = database.get_all() 54 | for i in range(len(result)): 55 | if result[i][4]==1: 56 | id_label_comp = QLabel() # id 57 | id_label_comp.setText(str(result[i][0])) 58 | title_label_comp = QLabel() # title 59 | title_label_comp.setText(result[i][1]) 60 | title_label_comp.setStyleSheet('font-size:18px') 61 | desc_label_comp = QLabel() # description 62 | desc_label_comp.setText(result[i][2]) 63 | desc_label_comp.setStyleSheet('font-size:18px') 64 | time_label_comp = QLabel() # time 65 | time_label_comp.setText(str(result[i][3])) 66 | time_label_comp.setStyleSheet('font-size:18px') 67 | 68 | self.ui.gridLayout_comp.addWidget(id_label_comp, i, 0) 69 | self.ui.gridLayout_comp.addWidget(title_label_comp, i, 1) 70 | self.ui.gridLayout_comp.addWidget(desc_label_comp, i, 2) 71 | self.ui.gridLayout_comp.addWidget(time_label_comp, i, 3) 72 | 73 | def readFromDataBase(self): 74 | result = database.get_all() 75 | self.lastID = 0 76 | for i in range(len(result)): 77 | self.lastID += 1 78 | 79 | done_checkbox = QCheckBox() 80 | done_checkbox.setObjectName(f'done_{result[i][0]}') 81 | done_checkbox.stateChanged.connect(self.doneTask) 82 | if result[i][4]==1: 83 | done_checkbox.setChecked(True) 84 | 85 | id_label = QLabel() # id 86 | id_label.setText(str(result[i][0])) 87 | 88 | title_label = QLabel() # title 89 | title_label.setText(result[i][1]) 90 | 91 | desc_label = QLabel() # description 92 | desc_label.setText(result[i][2]) 93 | 94 | time_label = QLabel() # time 95 | time_label.setText(str(result[i][3])) 96 | 97 | prio_btn = QPushButton() # priority 98 | prio_btn.setObjectName(f'prio_btn_{result[i][0]}') 99 | prio_btn.clicked.connect(self.priority) 100 | if result[i][5]==1: 101 | prio_btn.setIcon(QIcon('images/pin.png')) 102 | else: 103 | prio_btn.setIcon(QIcon('images/unpin.png')) 104 | 105 | detail_btn = QPushButton() # detail 106 | detail_btn.setObjectName(f'detail_btn_{result[i][0]}') 107 | detail_btn.setIcon(QIcon('images/detail.png')) 108 | detail_btn.clicked.connect(self.detail) 109 | 110 | dlt_btn = QPushButton() # delete 111 | dlt_btn.setObjectName(f'delete_btn_{result[i][0]}') 112 | dlt_btn.clicked.connect(self.delete) 113 | dlt_btn.setText('❌') 114 | 115 | # tasks layout 116 | self.ui.gridLayout.addWidget(id_label, i, 0) 117 | self.ui.gridLayout.addWidget(title_label, i, 1) 118 | self.ui.gridLayout.addWidget(desc_label, i, 2) 119 | self.ui.gridLayout.addWidget(time_label, i, 3) 120 | self.ui.gridLayout.addWidget(done_checkbox, i, 4) 121 | self.ui.gridLayout.addWidget(prio_btn, i, 5) 122 | self.ui.gridLayout.addWidget(detail_btn, i, 6) 123 | self.ui.gridLayout.addWidget(dlt_btn, i, 7) 124 | 125 | def doneTask(self): 126 | id = self.sender().objectName().split('_')[-1] 127 | if self.sender().isChecked(): 128 | database.update_done(id, 1) 129 | else: 130 | database.update_done(id, 0) 131 | 132 | def clearUI_tasks(self): 133 | for i in reversed(range(self.ui.gridLayout.count())): 134 | self.ui.gridLayout.itemAt(i).widget().deleteLater() 135 | 136 | def detail(self): 137 | id = self.sender().objectName().split('_')[-1] 138 | self.ui = Popup(id) 139 | 140 | def delete(self): 141 | id = self.sender().objectName().split('_')[-1] 142 | database.delete(id) 143 | self.clearUI_tasks() 144 | self.readFromDataBase() 145 | 146 | def priority(self): 147 | id = self.sender().objectName().split('_')[-1] 148 | priority = database.get_detail(id)[0][5] 149 | if priority==1: 150 | database.update_priority(id, 0) 151 | else: 152 | database.update_priority(id, 1) 153 | self.clearUI_tasks() 154 | self.readFromDataBase() 155 | 156 | def addNewTaskToDataBase(self): 157 | title = self.ui.tb_title.text() 158 | description = self.ui.tb_description.text() 159 | time = self.ui.tb_time.text() 160 | id = self.lastID + 1 161 | 162 | database.add(id, title, description, time) 163 | 164 | self.clearUI_tasks() 165 | self.readFromDataBase() 166 | 167 | self.ui.tb_title.setText('') 168 | self.ui.tb_description.setText('') 169 | self.ui.tb_time.setText('') 170 | 171 | app = QApplication([]) 172 | window = MainWindow() 173 | app.exec() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-Assignments 2 | 3 | 4 | ## Assignment 11 5 | - **Snake**: Simple snake in Python using Arcade library. 6 | > ![snake](https://user-images.githubusercontent.com/77120507/132943026-db97476e-c84d-4034-b14b-6821727658cc.png) 7 | - **Complex loops**: Draw red and blue diamond in Python using Arcade library. 8 | > ![complex loops](https://user-images.githubusercontent.com/77120507/132943114-41a644e1-865c-4ffe-964e-3681c0a4a668.png) 9 | ## Assignment 12 10 | **Silver Spacecraft** 11 | - Silver Spacecraft in **Python** using **Arcade** library. 12 | - [x] when bullet hit enemy spacecraft they will explode. 13 | - [x] enemy will come between 2-6 sec randomly. 14 | - [x] when enemy or list disappear from the screen their object will be remove. 15 | - [x] show 3 heart in bottom left. 16 | - [x] show score in bottom right. 17 | - [x] show Game over when user lose all their health. 18 | - [x] play sound when shooting. 19 | - [x] play sound when enemy spacecraft explode. 20 | - space craft view 21 | > ![Silver Spacecraft](https://user-images.githubusercontent.com/77120507/133397753-32b502ed-78c4-45ac-bb44-f09c2597d0e5.png) 22 | ## Assignment 13 23 | ## Assignment 14 24 | - **T-rex runner** 25 | - [x] Jump over cacti 26 | - [x] Bending in the face of birds 27 | - [x] jump sound 28 | - [x] Day and Night mode 29 | - [x] Speed up the game over time 30 | - [x] The current score is displayed next to the highest score 31 | - Trex view 1 32 | > ![Screenshot (486)](https://user-images.githubusercontent.com/77120507/134362351-3ae93ba5-b88b-4003-a292-37731621bb30.png) 33 | - Trex view 2 34 | > ![Screenshot (492)](https://user-images.githubusercontent.com/77120507/134362477-bf5d6f8c-c886-4c80-9d0e-2e5e80f1b5d1.png) 35 | ## Assignment 15 36 | ## Assignment 16 37 | - **Calculator** 38 | - Simple GUI calculator in **Python** using **pyqt6** 39 | - feautures: 40 | - [x] + - * / 41 | - [x] sin, cos, tan, cot 42 | - [x] log, sqrt 43 | - view: 44 | > ![calculator view](https://user-images.githubusercontent.com/77120507/135714897-cba6ec69-a3e1-4105-aee2-5ee9d70dc8c9.png) 45 | ## Assignment 17 46 | #### Tik Tok Toe 47 | - Tik Tok Toe game in **Python** using PySide6. 48 | - features: 49 | - [x] Single player(with AI) and two player 50 | - [x] Scoreboard 51 | - [x] About button 52 | - view: 53 | > ![TikTokToe](https://user-images.githubusercontent.com/77120507/136216879-d66e160e-823f-4f67-b4e4-93a4ba6faacc.png) 54 | 55 | ## Assignment 18 56 | #### Sudoku 57 | - Sudoku game written in **Python** using **Pyside6**. 58 | - features: 59 | - [x] check sudoku while you are playing it. 60 | - [x] dark mode on/off 61 | - [x] text align 62 | - [x] error handling when data missing 63 | - [x] make main numbers read-only 64 | - [x] win check 65 | - views: 66 | > ![sudoku1](https://user-images.githubusercontent.com/77120507/137157822-c7e2eec3-73a4-450a-b089-4bba6aeb0785.png) 67 | > ![sudoku2](https://user-images.githubusercontent.com/77120507/137157874-f0c4a332-87ac-4a70-9731-b1356f20ba96.png) 68 | > ![sudoku3](https://user-images.githubusercontent.com/77120507/137157902-5c2b2055-d6e0-4ef2-931c-bd69eec62e54.png) 69 | 70 | #### Unit Converter 71 | - Simple GUI unit converter written in **Python** using **Pyside** and **unit_converter**. 72 | - features: 73 | - [x] Support Length - Mass - Value - Temperature 74 | - view: 75 | > ![unitConverter](https://user-images.githubusercontent.com/77120507/137158223-108c61d7-77e5-43b6-a676-0ebbbbe1eb4c.png) 76 | 77 | #### Guess the number 78 | - A simple game written in **Python** using **PySide6**. 79 | - view: 80 | > ![guessTheNumber](https://user-images.githubusercontent.com/77120507/136650010-5bcb6f2e-d9ab-42f9-8f6c-90eebf441af6.png) 81 | #### Password Generator 82 | - Password Generator app written in **Python** using **PySide6**. 83 | - features: 84 | - [x] Three modes for generating passwords. weak, normal and unbreakable 85 | - view: 86 | > ![passwordGenerator](https://user-images.githubusercontent.com/77120507/136650056-ff51b41d-9b22-4e60-98ab-54688f80f575.png) 87 | #### Translator 88 | - Translator app written in **Python** using **PySide6**. 89 | - features: 90 | - [x] Support En to Fa and Fa to en 91 | - views: 92 | > ![Translator_fig1](https://user-images.githubusercontent.com/77120507/136650111-d666bc12-aeee-4901-b39b-6a7372107c52.png) 93 | > ![Translator_fig2](https://user-images.githubusercontent.com/77120507/136650114-b88cedfa-d0a8-4695-985f-e969478df27b.png) 94 | 95 | ## Assignment 20 96 | #### To-Do list 97 | - GUI to-do list written in **python** designed with **pyqt** and using **sqlite** database. 98 | - feautures: 99 | - [x] Detail button with unique window. 100 | - [x] Delete task. 101 | - [x] Add new task. 102 | - [x] Pin important tasks for higher priority. 103 | - [x] Designed with 2 tabs for better user experience, all-tasks and Done tasks. 104 | - views: 105 | > ![todolist1](https://user-images.githubusercontent.com/77120507/139032396-c6a5e1d3-2abb-48a0-89c8-099972497726.png) 106 | > ![todolist2](https://user-images.githubusercontent.com/77120507/139032429-4027b4c2-b2a2-4699-8a83-05e104f6c022.png) 107 | > ![todolist3](https://user-images.githubusercontent.com/77120507/139032452-78f46f5d-07c1-41d4-9573-d02cc2676ef4.png) 108 | 109 | #### AI Snake 110 | - A clever snake that can find the apple! 111 | - Written in **python** using **arcade** library. 112 | - view: 113 | > ![AIsnake](https://user-images.githubusercontent.com/77120507/139032617-a3edb07e-02d0-4499-a553-f89e5f0b79ac.png) 114 | 115 | #### Telegram Bot 116 | - a telegram bot written in **python** using **py-telegrambot-api**. 117 | - New feature: 118 | - added /note to bot commands. 119 | 120 | ## Assignment 21 121 | #### Checkered Board 122 | - Create a chess table using **numpy** and **opencv**. 123 | - view: 124 | - ![result_1](https://user-images.githubusercontent.com/77120507/139427129-565d93a9-97eb-44bb-b261-0a3c5d1a6164.png) 125 | #### Color Correction 126 | - Reverse black and white colors with opencv. 127 | - views: 128 | - ![result_2_1](https://user-images.githubusercontent.com/77120507/139427174-2e5f3403-fae6-44b4-b560-76f76b8014f7.png) 129 | - ![result_2_2](https://user-images.githubusercontent.com/77120507/139427186-fbc246f3-1e6a-4648-9e0e-cdcccaff4c27.png) 130 | #### Rotate Image 131 | - Rotate an image with for loop in opencv(without cv2.rotate) 132 | - view: 133 | - ![result_3](https://user-images.githubusercontent.com/77120507/139427258-d31aafcc-0fc7-4706-8334-c9a011ab0ca1.png) 134 | #### Color Separation 135 | - Separate object of black-whte image using opencv and threshold method. 136 | - view: 137 | - ![result_4](https://user-images.githubusercontent.com/77120507/139429837-e7538f85-af2c-4f25-9ed3-7dd9a28d2fed.png) 138 | #### Corner Line 139 | - Create a black line in top left corner.(without opencv built-in methods) 140 | - view: 141 | - ![result_5](https://user-images.githubusercontent.com/77120507/139429884-e7c9eb8a-a124-4232-ab79-b4e3a5f42468.png) 142 | #### Gradient 143 | - Create an image with whito-black gradient using **open-cv** and **numpy**. 144 | - view: 145 | - ![result_6](https://user-images.githubusercontent.com/77120507/139590566-7a676885-cb49-43a3-89d1-fa3d02c9386a.png) 146 | #### Letter B 147 | - Design letter B using **numpy** and **open-cv**. 148 | - view: 149 | - ![result_7](https://user-images.githubusercontent.com/77120507/139590558-05787f52-7c96-4669-ad1a-4a1050380378.png) 150 | 151 | 152 | -------------------------------------------------------------------------------- /Assignment20/to do/popup.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 462 10 | 475 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | Detail 21 | 22 | 23 | 24 | images/detail_icon.pngimages/detail_icon.png 25 | 26 | 27 | 28 | 29 | 0 30 | 0 31 | 32 | 33 | 34 | 35 | 36 | 37 | 10 38 | 39 | 40 | 10 41 | 42 | 43 | 10 44 | 45 | 46 | 10 47 | 48 | 49 | 20 50 | 51 | 52 | 7 53 | 54 | 55 | 56 | 57 | 58 | 12 59 | true 60 | 61 | 62 | 63 | Title : 64 | 65 | 66 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 12 75 | true 76 | 77 | 78 | 79 | Description : 80 | 81 | 82 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 12 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 12 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 12 115 | true 116 | 117 | 118 | 119 | ID : 120 | 121 | 122 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 12 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 12 143 | true 144 | 145 | 146 | 147 | Done : 148 | 149 | 150 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 12 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 12 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 12 183 | true 184 | 185 | 186 | 187 | Time : 188 | 189 | 190 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 10 202 | true 203 | 204 | 205 | 206 | background-color: rgb(121, 85, 72); 207 | color: rgb(255, 255, 255); 208 | 209 | 210 | Back to Tasks >> 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 0 222 | 0 223 | 462 224 | 22 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | -------------------------------------------------------------------------------- /Assignment14/T-rex runner/main.py: -------------------------------------------------------------------------------- 1 | import random 2 | import time 3 | import arcade 4 | from cactus import Cactus 5 | from pterodactyl import Pterodactyl 6 | from dino import Dino 7 | from ground import Ground 8 | DEFAULT_FONT_SIZE = 40 9 | class Game(arcade.Window): 10 | def __init__(self): 11 | self.w = 800 12 | self.h = 600 13 | self.gravity = 0.3 14 | super().__init__(self.w , self.h ,"T-rex runner by Benyamin Zojaji") 15 | self.backeground_night_image = arcade.load_texture("images/background_night.png") 16 | self.backeground_day_image = arcade.load_texture("images/background_day.png") 17 | self.gameOver = False 18 | self.night = True 19 | self.cactus_speed = -4 20 | self.pterodactyl_speed = -5 21 | self.time_score = time.time() 22 | self.time_cactus = time.time() 23 | self.time_pterodactyl = time.time() 24 | self.time_backgroundChange = time.time() 25 | self.cactus_list = arcade.SpriteList() 26 | self.pterodactyl_list = arcade.SpriteList() 27 | self.dino = Dino() 28 | self.moon = arcade.Sprite('images/moon.png') 29 | self.moon.center_x = self.w 30 | self.moon.center_y = random.randint(400, 600) 31 | self.moon.change_x = -0.5 32 | self.moon.change_y = 0 33 | self.star = arcade.Sprite('images/star.png') 34 | self.star.center_x = self.w 35 | self.star.center_y = random.randint(250, 750) 36 | self.star.change_x = -1 37 | self.star.change_y = 0 38 | self.cloud = arcade.Sprite('images/cloud_night.png') 39 | self.cloud.center_x = self.w 40 | self.cloud.center_y = random.randint(350, 750) 41 | self.cloud.change_x = -1.5 42 | self.cloud.change_y = 0 43 | self.ground_list = arcade.SpriteList() 44 | for i in range(0, self.w, 64): 45 | ground = Ground(i ,100) 46 | self.ground_list.append(ground) 47 | self.physics_engine = arcade.PhysicsEnginePlatformer(self.dino, self.ground_list, self.gravity) 48 | def on_draw(self): 49 | self.time_now = time.time() 50 | if self.gameOver: 51 | if self.night: 52 | arcade.draw_text('YOU Lose', self.w//2-200, self.h//2, arcade.color.WHITE, DEFAULT_FONT_SIZE, width=400, font_name='Kenney Mini Square', align='center') 53 | arcade.draw_text('Press R for reset game', self.w//2-200, self.h//2-100, arcade.color.WHITE, DEFAULT_FONT_SIZE//2, width=400, font_name='Kenney Mini Square', align='center') 54 | else: 55 | arcade.draw_text('YOU Lose', self.w//2-200, self.h//2, arcade.color.BLACK, DEFAULT_FONT_SIZE, width=400, font_name='Kenney Mini Square', align='center') 56 | arcade.draw_text('Press R for reset game', self.w//2-200, self.h//2-100, arcade.color.BLACK, DEFAULT_FONT_SIZE//2, width=400, font_name='Kenney Mini Square', align='center') 57 | else: 58 | arcade.start_render() 59 | if self.time_now - self.time_backgroundChange > 15: 60 | self.time_backgroundChange = time.time() 61 | if self.night: 62 | self.night = False 63 | else: 64 | self.night = True 65 | if self.night: 66 | arcade.draw_lrwh_rectangle_textured(0, 0, self.w, self.h, self.backeground_night_image) 67 | else: 68 | arcade.draw_lrwh_rectangle_textured(0, 0, self.w, self.h, self.backeground_day_image) 69 | for ground in self.ground_list: 70 | ground.draw() 71 | for cactus in self.cactus_list: 72 | cactus.draw() 73 | for pterodactyl in self.pterodactyl_list: 74 | pterodactyl.draw() 75 | self.moon.draw() 76 | self.cloud.draw() 77 | self.star.draw() 78 | self.dino.draw() 79 | if self.night: 80 | arcade.draw_text('HI %s %s' %(str(self.dino.highScore).zfill(5), str(self.dino.score).zfill(5)), self.w-220, self.h-30, arcade.color.WHITE, DEFAULT_FONT_SIZE//2, width=400, font_name='Kenney Mini Square', align='left') 81 | else: 82 | arcade.draw_text('HI %s %s' %(str(self.dino.highScore).zfill(5), str(self.dino.score).zfill(5)), self.w-220, self.h-30, arcade.color.BLACK, DEFAULT_FONT_SIZE//2, width=400, font_name='Kenney Mini Square', align='left') 83 | def on_update(self, delta_time: float): 84 | self.time_now = time.time() 85 | if not self.gameOver: 86 | self.dino.score = int(self.time_now-self.time_score) 87 | if self.dino.score-self.dino.score_speed>15: 88 | self.dino.score_speed += 15 89 | self.cactus_speed -= 0.3 90 | self.pterodactyl_speed -= 0.5 91 | self.physics_engine.update() 92 | for pterodactyl in self.pterodactyl_list: 93 | pterodactyl.update_animation() 94 | if not self.dino.down: 95 | self.dino.update_animation() 96 | else: 97 | self.dino.manual_walkDown_animation() 98 | self.dino.down_frame += 1 99 | for ground in self.ground_list: 100 | if ground.center_x<0: 101 | self.ground_list.remove(ground) 102 | gr = Ground(self.w-64 ,100) 103 | self.ground_list.append(gr) 104 | if self.time_now - self.time_cactus > 4 : 105 | new_cactus = Cactus(self.w, 200, self.cactus_speed) 106 | self.cactus_list.append(new_cactus) 107 | self.time_cactus = time.time() 108 | if self.time_now - self.time_pterodactyl > 10 : 109 | new_pterodactyl = Pterodactyl(self.w, 200, self.pterodactyl_speed) 110 | self.pterodactyl_list.append(new_pterodactyl) 111 | self.time_pterodactyl = time.time() 112 | for cactus in self.cactus_list: 113 | cactus.update() 114 | if cactus.center_x < 0: 115 | self.cactus_list.remove(cactus) 116 | for pterodactyl in self.pterodactyl_list: 117 | pterodactyl.update() 118 | if pterodactyl.center_x<0: 119 | self.pterodactyl_list.remove(pterodactyl) 120 | if self.moon.center_x<0 or not self.moon: 121 | self.moon.center_x = self.w 122 | self.moon.center_y = random.randint(400, 600) 123 | if self.star.center_x<300 or not self.star: 124 | self.star.center_x = self.w 125 | self.star.center_y = random.randint(250, 750) 126 | if self.cloud.center_x<50 or not self.cloud: 127 | self.cloud.center_x = self.w 128 | self.cloud.center_y = random.randint(350, 750) 129 | self.moon.update() 130 | self.star.update() 131 | self.cloud.update() 132 | self.dino.set_x() 133 | for cactus in self.cactus_list: 134 | if arcade.check_for_collision(self.dino, cactus): 135 | self.gameOver = True 136 | for pterodactyl in self.pterodactyl_list: 137 | if arcade.check_for_collision(self.dino, pterodactyl): 138 | self.gameOver = True 139 | def on_key_press(self, key, modifiers): 140 | if key==arcade.key.UP: 141 | if self.physics_engine.can_jump(): 142 | self.dino.change_y = 12 143 | self.dino.jump_sound() 144 | elif key==arcade.key.DOWN: 145 | self.dino.down = True 146 | elif key==arcade.key.R and self.gameOver: 147 | self.gameOver = False 148 | if self.dino.score > self.dino.highScore: 149 | self.dino.highScore = self.dino.score 150 | self.dino.write_highScore() 151 | self.dino.score = 0 152 | self.time_score = time.time() 153 | self.cactus_speed = -4 154 | self.pterodactyl_speed = -5 155 | def on_key_release(self, key, modifiers): 156 | if key==arcade.key.DOWN: 157 | self.dino.down = False 158 | if __name__ == '__main__': 159 | game = Game() 160 | arcade.run() 161 | -------------------------------------------------------------------------------- /Assignment18/converter/unitConverter.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 382 10 | 217 11 | 12 | 13 | 14 | Unit Converter 15 | 16 | 17 | 18 | icon.jpgicon.jpg 19 | 20 | 21 | background-color: rgb(196, 255, 169); 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | true 30 | 31 | 32 | 33 | To 34 | 35 | 36 | Qt::AlignCenter 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 0 45 | 0 46 | 47 | 48 | 49 | background-color: rgb(255, 255, 255); 50 | 51 | 52 | 53 | g 54 | 55 | 56 | 57 | 58 | kg 59 | 60 | 61 | 62 | 63 | T 64 | 65 | 66 | 67 | 68 | P 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Qt::Vertical 77 | 78 | 79 | 80 | 20 81 | 40 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 0 91 | 0 92 | 93 | 94 | 95 | background-color: rgb(255, 255, 255); 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 0 104 | 0 105 | 106 | 107 | 108 | 109 | 10 110 | true 111 | 112 | 113 | 114 | background-color: rgb(255, 52, 52); 115 | 116 | 117 | Convert 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | true 126 | 127 | 128 | 129 | Output 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | true 138 | 139 | 140 | 141 | From 142 | 143 | 144 | Qt::AlignCenter 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 0 153 | 0 154 | 155 | 156 | 157 | background-color: rgb(255, 255, 255); 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 0 166 | 0 167 | 168 | 169 | 170 | background-color: rgb(255, 255, 255); 171 | 172 | 173 | 174 | kg 175 | 176 | 177 | 178 | 179 | g 180 | 181 | 182 | 183 | 184 | T 185 | 186 | 187 | 188 | 189 | P 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 9 199 | true 200 | 201 | 202 | 203 | Input 204 | 205 | 206 | 0 207 | 208 | 209 | -1 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | true 218 | 219 | 220 | 221 | Convert 222 | 223 | 224 | Qt::AlignCenter 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 12 233 | true 234 | 235 | 236 | 237 | = 238 | 239 | 240 | Qt::AlignCenter 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 0 249 | 0 250 | 251 | 252 | 253 | background-color: rgb(255, 255, 255); 254 | 255 | 256 | 257 | Mass 258 | 259 | 260 | 261 | 262 | Length 263 | 264 | 265 | 266 | 267 | Value 268 | 269 | 270 | 271 | 272 | Temperature 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 0 283 | 0 284 | 382 285 | 22 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | -------------------------------------------------------------------------------- /Assignment20/telegram bot/main.py: -------------------------------------------------------------------------------- 1 | from random import * 2 | from khayyam import JalaliDatetime 3 | from gtts import gTTS 4 | import pysynth as ps 5 | import telebot 6 | import qrcode 7 | 8 | TOKEN = '' 9 | bot = telebot.TeleBot(TOKEN) 10 | 11 | 12 | @bot.message_handler(commands=['start']) 13 | def start_func(message): 14 | bot.send_message(message.chat.id, 'Welcome ' + (message.chat.first_name) + '!') 15 | 16 | 17 | RANDOM_NUMBER = randint(0, 99) 18 | 19 | 20 | def new_randomNumber(): 21 | global RANDOM_NUMBER 22 | RANDOM_NUMBER = randint(0, 99) 23 | 24 | 25 | @bot.message_handler(commands=['game']) 26 | def game_func(m): 27 | msg = bot.send_message(m.chat.id, 'lets play!\nTo make it easier number is between 0-100\nGuess the number!') 28 | bot.register_next_step_handler(msg, gm1) 29 | 30 | 31 | def gm1(m): 32 | markup = telebot.types.ReplyKeyboardMarkup(row_width=1) 33 | btn1 = telebot.types.KeyboardButton('NEW Game') 34 | markup.add(btn1) 35 | if not m.text.startswith("/"): 36 | try: 37 | if m.text == 'NEW Game': 38 | new_randomNumber() 39 | bot.send_message(m.chat.id, 'NEW Game begin. Guess new number:', 40 | reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 41 | bot.register_next_step_handler_by_chat_id(m.chat.id, gm1) 42 | elif int(m.text) < RANDOM_NUMBER: 43 | msg = bot.send_message(m.chat.id, 'bigger', reply_markup=markup) 44 | bot.register_next_step_handler(msg, gm1) 45 | elif int(m.text) > RANDOM_NUMBER: 46 | msg = bot.send_message(m.chat.id, 'lower', reply_markup=markup) 47 | bot.register_next_step_handler(msg, gm1) 48 | elif int(m.text) == RANDOM_NUMBER: 49 | msg = bot.send_message(m.chat.id, 'Thats right. ^^', 50 | reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 51 | except ValueError: 52 | bot.send_message(m.chat.id, 'something is wrong with your input. give me a number 😢', 53 | reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 54 | except: 55 | bot.send_message(m.chat.id, 'something is wrong. Call my dad 😭\n@mrbni Error code:gm1', 56 | reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 57 | else: 58 | bot.reply_to(m, 'I expect a number not a command. 🤔') 59 | bot.send_message(m.chat.id, 'now tell me your command.') 60 | 61 | 62 | @bot.message_handler(commands=['age']) 63 | def age_func(m): 64 | msg = bot.send_message(m.chat.id, 'Just give me your date of birth ^^ e.g. 1360/4/12') 65 | bot.register_next_step_handler(msg, age1) 66 | 67 | 68 | def age1(m): 69 | if not m.text.startswith('/'): 70 | userBirth = m.text.split('/') 71 | if len(userBirth) == 3: 72 | difference = JalaliDatetime.now() - JalaliDatetime(userBirth[0], userBirth[1], userBirth[2]) 73 | bot.send_message(m.chat.id, 'You are about ' + str(difference.days // 365)) 74 | else: 75 | bot.reply_to(m, 'something is wrong with your input.') 76 | else: 77 | bot.reply_to(m, 'I expect your date of birth not a command. 🤔') 78 | bot.send_message(m.chat.id, 'now tell me your command.') 79 | 80 | 81 | @bot.message_handler(commands=['voice']) 82 | def voice_func(m): 83 | msg = bot.send_message(m.chat.id, 'Just give me your text ^^ e.g. Hey there') 84 | bot.register_next_step_handler(msg, vc1) 85 | 86 | 87 | def vc1(m): 88 | if not m.text.startswith('/'): 89 | try: 90 | vc = gTTS(text=m.text, slow=False) 91 | vc.save('voice.ogg') 92 | voice = open('voice.ogg', 'rb') 93 | bot.send_voice(m.chat.id, voice) 94 | except: 95 | bot.send_message(m.chat.id, 'something is wrong. Call my dad 😭\n@mrbni Error code:vc1') 96 | else: 97 | bot.reply_to(m, 'I expect text not a command. 🤔') 98 | bot.send_message(m.chat.id, 'now tell me your command.') 99 | 100 | 101 | @bot.message_handler(commands=['max']) 102 | def max_func(m): 103 | msg = bot.send_message(m.chat.id, 'Just give me your numbers seprated with , ^^ e.g. 3,5,10,2,15,4') 104 | bot.register_next_step_handler(msg, mx1) 105 | 106 | 107 | def mx1(m): 108 | if not m.text.startswith('/'): 109 | try: 110 | numbers = list(map(int, m.text.split(','))) 111 | bot.send_message(m.chat.id, 'biggest number: ' + str(max(numbers))) 112 | except ValueError: 113 | bot.reply_to(m, 'Is that a number??😶') 114 | except: 115 | bot.send_message(m.chat.id, 'something is wrong. Call my dad 😭\n@mrbni Error code:mx1') 116 | else: 117 | bot.reply_to(m, 'I expect numbers not a command. 🤔') 118 | bot.send_message(m.chat.id, 'now tell me your command.') 119 | 120 | 121 | @bot.message_handler(commands=['argmax']) 122 | def argmax_welcome(m): 123 | msg = bot.send_message(m.chat.id, 'Just give me your numbers seprated with , ^^ e.g. 3,5,10,2,15,4') 124 | bot.register_next_step_handler(msg, agmx1) 125 | 126 | 127 | def agmx1(m): 128 | if not m.text.startswith('/'): 129 | try: 130 | numbers = list(map(int, m.text.split(','))) 131 | bot.send_message(m.chat.id, 'biggest number index: ' + str(numbers.index(max(numbers)))) 132 | except ValueError: 133 | bot.reply_to(m, 'Is that a number??😶') 134 | except: 135 | bot.send_message(m.chat.id, 'something is wrong. Call my dad 😭\n@mrbni Error code:agmx1') 136 | else: 137 | bot.reply_to(m, 'I expect numbers not a command. 🤔') 138 | bot.send_message(m.chat.id, 'now tell me your command.') 139 | 140 | 141 | @bot.message_handler(commands=['qrcode']) 142 | def qrcode_func(m): 143 | msg = bot.send_message(m.chat.id, 'Just give me your text/url/... , ^^ e.g. https://t.me/mrbni') 144 | bot.register_next_step_handler(msg, qr1) 145 | 146 | 147 | def qr1(m): 148 | if not m.text.startswith('/'): 149 | try: 150 | img = qrcode.make(m.text) 151 | img.save('QRCODE.png') 152 | photo = open('QRCODE.png', 'rb') 153 | bot.send_photo(m.chat.id, photo) 154 | except: 155 | bot.send_message(m.chat.id, 'something is wrong. Call my dad 😭\n@mrbni Error code:qr1') 156 | else: 157 | bot.reply_to(m, 'I expect numbers not a command. 🤔') 158 | bot.send_message(m.chat.id, 'now tell me your command.') 159 | 160 | 161 | SONG = () 162 | NOTE = '' 163 | STRETCH = '' 164 | 165 | 166 | def add_note(): 167 | global SONG 168 | global NOTE 169 | global STRETCH 170 | if NOTE == 'Do': 171 | NOTE = 'c' 172 | elif NOTE == 'Re': 173 | NOTE = 'd' 174 | elif NOTE == 'Mi': 175 | NOTE = 'e' 176 | elif NOTE == 'Fa': 177 | NOTE = 'f' 178 | elif NOTE == 'Sol': 179 | NOTE = 'g' 180 | elif NOTE == 'La': 181 | NOTE = 'a' 182 | else: 183 | NOTE = 'b' 184 | if STRETCH == 'Whole': 185 | STRETCH = 1 186 | elif STRETCH == 'Half': 187 | STRETCH = 2 188 | elif STRETCH == 'Quarter': 189 | STRETCH = 4 190 | elif STRETCH == 'Eighth': 191 | STRETCH = 8 192 | else: 193 | STRETCH = 16 194 | SONG += ((NOTE, STRETCH),) 195 | NOTE = '' 196 | STRETCH = '' 197 | 198 | 199 | def set_note(name): 200 | global NOTE 201 | NOTE = name 202 | 203 | 204 | def set_stretch(stroke): 205 | global STRETCH 206 | STRETCH = stroke 207 | 208 | 209 | def empty_song(): 210 | global SONG 211 | SONG = () 212 | 213 | 214 | @bot.message_handler(commands=['song']) 215 | def song_func(m): 216 | markup = telebot.types.ReplyKeyboardMarkup(row_width=1) 217 | btn1 = telebot.types.KeyboardButton('Lets GO!') 218 | markup.add(btn1) 219 | m = bot.send_message(m.chat.id, 'lets make a song!\npress 📤 when you are done.', reply_markup=markup) 220 | bot.register_next_step_handler(m, so1) 221 | 222 | 223 | def so1(m): 224 | if not m.text.startswith('/'): 225 | if m.text != 'Lets GO!': 226 | set_stretch(m.text) 227 | if STRETCH != '' and NOTE != '': 228 | add_note() 229 | markup = telebot.types.ReplyKeyboardMarkup(row_width=4) 230 | btn1 = telebot.types.KeyboardButton('Do') 231 | btn2 = telebot.types.KeyboardButton('Re') 232 | btn3 = telebot.types.KeyboardButton('Mi') 233 | btn4 = telebot.types.KeyboardButton('Fa') 234 | btn5 = telebot.types.KeyboardButton('Sol') 235 | btn6 = telebot.types.KeyboardButton('La') 236 | btn7 = telebot.types.KeyboardButton('Si') 237 | btn8 = telebot.types.KeyboardButton('📤') 238 | markup.add(btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8) 239 | msg = bot.send_message(m.chat.id, 'note:', reply_markup=markup) 240 | bot.register_next_step_handler(msg, so2) 241 | else: 242 | bot.reply_to(m, 'I expect notes not a command. 🤔', 243 | reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 244 | bot.send_message(m.chat.id, 'now tell me your command.') 245 | 246 | 247 | def so2(m): 248 | if not m.text.startswith('/'): 249 | if not m.text == '📤': 250 | set_note(m.text) 251 | markup = telebot.types.ReplyKeyboardMarkup(row_width=3) 252 | btn1 = telebot.types.KeyboardButton('Whole') 253 | btn2 = telebot.types.KeyboardButton('Half') 254 | btn3 = telebot.types.KeyboardButton('Quarter') 255 | btn4 = telebot.types.KeyboardButton('Eighth') 256 | btn5 = telebot.types.KeyboardButton('Sixteenth') 257 | markup.add(btn1, btn2, btn3, btn4, btn5) 258 | msg = bot.send_message(m.chat.id, 'stretch:', reply_markup=markup) 259 | bot.register_next_step_handler(msg, so1) 260 | else: 261 | try: 262 | if len(SONG) >= 1: 263 | bot.send_message(m.chat.id, 'Here is your song:', 264 | reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 265 | ps.make_wav(SONG, fn="song.wav") 266 | empty_song() 267 | song = open('song.wav', 'rb') 268 | bot.send_voice(m.chat.id, song) 269 | else: 270 | bot.send_message(m.chat.id, 'Just try me once!\nI won\'t let you down(just kidding, I will 😂).', 271 | reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 272 | except: 273 | bot.send_message(m.chat.id, 'something is wrong. Call my dad 😭\n@mrbni Error code:so2', 274 | reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 275 | else: 276 | bot.reply_to(m, 'I expect notes not a command. 🤔', 277 | reply_markup=telebot.types.ReplyKeyboardRemove(selective=True)) 278 | bot.send_message(m.chat.id, 'now tell me your command.') 279 | 280 | 281 | @bot.message_handler(commands=['help']) 282 | def help_func(message): 283 | bot.reply_to(message, 284 | 'For any issues pls contact my creator.\nbenyamin.zojaji@gmail.com\n/game -guess the number game 🎮\n/song -create your song 🎶\n/age -calculate your age 🧍\n/voice -convert text to voice 🎼\n/max -find biggest number ✔️\n/argmax -find index of biggest number ☑️\n/qrcode -make Qrcode 🧷\n/help -show commands ℹ️') 285 | 286 | 287 | bot.polling(none_stop=True) 288 | --------------------------------------------------------------------------------