Nexclap

Bike Crash severity using logistic regression

https://colab.research.google.com/drive/1SWle_HOg5DyJS8EiLARbZcn7qgLXnoef#scrollTo=Wv6NmcOqaDFo&line=1&uniqifier=1

Function compilation

#In this program I have compiled some functions and let the user choose which one #they want to use. The aproach that I took when solving this problem is instead of #defining the functions first made it so that only the chosen function is defined # and the others are defined once the user chooses them. #Prithvi #In this program instead of defining all of the functions and then giving the commands, I programmed it so each function is only defined after I choose it while True: #Here I made it so that all of the functions would be put inside a loop so if 1 ended it would ask you the question again The_Question = input("what function would you like me to run?") if The_Question == "prime": def prime(): number = int(input("Enter The Number")) # In my primecomposite program I made it so that it was in an infinite loop so that once it ended t would break into the infinite loop again if number > 1: for i in range(2,int(number/2)): if (number % i == 0): print(number, "is not a Prime Number") break else: print(number,"is a Prime number") #I added the question to stop and try another function to make the program easier to make it more user friendly VB = input(" would you like to continue?") if VB == "yes": prime() else: return prime() if The_Question == "calendar": import calendar while 8==8: # by saying "while 8==8" I am creating an infinite loop #The print_month function is only defined b = (input("would you like to print out the calendar for a month or a year month/year ")) def print_month(): c = int(input("What year would you like the month to be from. ex. 2020 ")) d = int(input("What month would you like to be printed 1 for january, 2 for febuary etc.. ")) print (calendar.month(c,d)) VB2 = input("would you like to continue") if VB2 == "yes": print_month() else: return def print_year(): e = int(input("Which year would you like the calendar be printed of 2015, 2019 etc ")) for i in range(1,13): print (calendar.month (e,i)) if b == "month": print_month() if b == "year": print_year() if The_Question == "miles and kilometers": f = input("Would you like to convert from kiliometer to mile or from mile to kilometer mtk/ktm? ") if f == "mtk": miles_question = int(input("How many miles would you like to convert? ")) if f == "ktm": kilometer_question = int(input("How many miles would you like to convert? ")) def mtk(): res1 = miles_question * 1.608 print(res1,"kilometers") def ktm(): res2 = kilometer_question * 0.621 print(res2,"miles") if f == "mtk": mtk() if f == "ktm": ktm() g = input("would you like to make another conversion? ") if g == "yes": 0+0 if g == "no": break # If the user answers with multiplication that he/she would then need to say if they want a table or just want to multiply 2 numbers. if The_Question =="multiplication": MYlist = [] h = (input("would you like to show the multiplication table or would you like to multiply two numbers? table/two_numbers")) if h == "table": j = int(input("how many multiplication tables would you like answer 1-10")) for i in range (0, j): k = int(input("what multiplication tables do you want 1,2,3 ect.")) MYlist.append(k) # Once the user is done inputing all of the data, the program appends it all into a list which is needed in the table function def multtable(): for x in MYlist: for y in range (1,11): result = x * y print(x,"x", y, "=", result) multtable() if h == "two_numbers": def two_numbermultiply(): val3 = val1 * val2 print(val1, " x ", val2," = ", val3) val1 = int(input("input a number to be multiplied")) val2 = int(input("input a second number")) two_numbermultiply()

snake game

snake game using curses

import random import curses import time pip install curses‑2.2‑cp36‑cp36m‑win_amd64.whl sc = curses.initscr() h, w = sc.getmaxyx() win = curses.newwin(h, w, 0, 0) win.keypad(1) curses.curs_set(0) snake_head = [10,15] snake_position = [[15,10],[14,10],[13,10]] apple_position = [20,20] score = 0 win.addch(apple_position[0], apple_position[1], curses.ACS_DIAMOND) key = curses.KEY_RIGHT def collision_with_boundaries(snake_head): if snake_head[0]>=h-1 or snake_head[0]<=0 or snake_head[1]>=w-1 or snake_head[1]<=0 : return 1 else: return 0 def collision_with_self(snake_position): snake_head = snake_position[0] if snake_head in snake_position[1:]: return 1 else: return 0 win.border(0) win.timeout(100) next_key = win.getch() if next_key == -1: key = key else: key = next_key if key == curses.KEY_LEFT and prev_button_direction != 1: button_direction = 0 elif key == curses.KEY_RIGHT and prev_button_direction != 0: button_direction = 1 elif key == curses.KEY_UP and prev_button_direction != 2: button_direction = 3 elif key == curses.KEY_DOWN and prev_button_direction != 3: button_direction = 2 else: pass prev_button_direction = button_direction if button_direction == 1: snake_head[1] += 1 elif button_direction == 0: snake_head[1] -= 1 elif button_direction == 2: snake_head[0] += 1 elif button_direction == 3: snake_head[0] -= 1 def collision_with_apple(score): apple_position = [random.randint(1,h-2),random.randint(1,w-2)] score += 1 return apple_position, score if snake_head == apple_position: apple_position, score = collision_with_apple(score) snake_position.insert(0, list(snake_head)) win.addch(apple_position[0], apple_position[1], curses.ACS_DIAMOND) else: snake_position.insert(0, list(snake_head)) last = snake_position.pop() win.addch(last[0], last[1], ' ') sc.addstr(10, 30, 'Your Score is: '+str(score)) sc.refresh() time.sleep(2) curses.endwin()
Announcements
  • Test Announcement from Nexclap

    Test message from nexclap - please ignore

    2023-02-13

  • Test message

    Test message from nexclap - please ignore

    2023-02-11

  • Test message

    Test message from nexclap - please ignore

    2023-02-11

  • View all