Here I'll post different projects I've done with programming.
Im very new to programming, and just startet learning javascript maby 2 weeks ago. So there wont be a lot of projects, and the projects will probably be very easy to accomplish.
But either way, I hope you find some value here.
Startpage
What is a startpage? A startpage is a page where you have usefull links and whatever else. Its like your browser startpage, but it's something you've made yourself.
There is also a discord for startpages, and a reddit page too.
Guess the number (Python)
import random
def guess(x):
random_number = random.randint(1, x)
guess = 0
while guess != random_number:
guess = int(input(f'Guess a number between 1 and {x}: '))
if guess < random_number:
print("Too low")
elif guess > random_number:
print("Too hight")
print("Cum")
guess(10)
Rock paper scissors (Python)
import random
def play():
user = input("'r' for rock, 'p' for paper, 's' for scissors")
computer = random.choice(['r', 'p', 's'])
if user == computer:
return 'tie'
if is_win(user, computer):
return 'You won!'
return 'lost'
def is_win(player, opponent):
if (player == 'r' and opponent == 's') or (player == 's' and opponent == 'p') or (player == 'p' and opponent == 'r'):
return True
print(play())
Login code (Python)
def login():
user_given_name = input('Whats your name?: ')
user_given_password = input('What do you want your password to be?: ')
while len(user_given_password) < 6:
print('Password must be at least 6 characters long!')
user_given_password = input('What do you want your password to be?: ')
password_again = input('Write password again: ')
while user_given_password != password_again:
print('Write a password you can remember')
user_given_password = input('What do you want your password to be?: ')
password_again = input('Write password again: ')
print('Youve succsessfully created an account!')
print('Username: ' + user_given_name)
print('Password: ' + user_given_password)
log_in = input('Do you want to log int?: Yes or No?: ').upper()
if log_in == 'YES':
print('Great!')
else:
print('Ok, see you later!')
return
check_name = input('Whats your username?: ')
check_password = input('Whats your password?: ')
if check_name == user_given_name and check_password == user_given_password:
print('Youve succsessfully logged in!')
login_tries = 3
while check_name != user_given_name or check_password != user_given_password:
login_tries = login_tries - 1
print(f'Either username or password is incorrect, please try again. You have {login_tries} tries left')
check_name = input('Whats your username?: ')
check_password = input('Whats your password?: ')
if check_name == user_given_name and check_password == user_given_password:
print('Youve succsessfully logged in!')
if login_tries == 1:
print('Sorry, your login-in was unsuccsessfull! ;(')
return
print(login())
Tic tac toe
positions = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
counter = 0
def board():
global counter
print(positions[0] + ' | ' + positions[1] + ' | ' + positions[2])
print(positions[3] + ' | ' + positions[4] + ' | ' + positions[5])
print(positions[6] + ' | ' + positions[7] + ' | ' + positions[8])
counter = counter + 1
print(counter)
play()
def play():
global counter
position = (input('Whats your move?: '))
position = int(position) - 1
if counter == 1:
positions[position] = 'o'
elif counter == 2:
positions[position] = 'x'
counter = 0
win_condition()
board()
def win_condition():
if positions[0] == 'x' and positions[1] == 'x' and positions[2] == 'x':
print('x won!')
return
if positions[3] == 'x' and positions[4] == 'x' and positions[5] == 'x':
print('x won!')
return
if positions[6] == 'x' and positions[7] == 'x' and positions[8] == 'x':
print('x won!')
return
if positions[0] == 'x' and positions[3] == 'x' and positions[6] == 'x':
print('x won!')
return
if positions[1] == 'x' and positions[4] == 'x' and positions[7] == 'x':
print('x won!')
return
if positions[2] == 'x' and positions[5] == 'x' and positions[8] == 'x':
print('x won!')
return
if positions[0] == 'x' and positions[4] == 'x' and positions[8] == 'x':
print('x won!')
return
if positions[2] == 'x' and positions[4] == 'x' and positions[6] == 'x':
print('x won!')
return
if positions[0] == 'o' and positions[1] == 'o' and positions[2] == 'o':
print('o won!')
return
if positions[3] == 'o' and positions[4] == 'o' and positions[5] == 'o':
print('o won!')
return
if positions[6] == 'o' and positions[7] == 'o' and positions[8] == 'o':
print('o won!')
return
if positions[0] == 'o' and positions[3] == 'o' and positions[6] == 'o':
print('o won!')
return
if positions[1] == 'o' and positions[4] == 'o' and positions[7] == 'o':
print('o won!')
return
if positions[2] == 'o' and positions[5] == 'o' and positions[8] == 'o':
print('o won!')
return
if positions[0] == 'o' and positions[4] == 'o' and positions[8] == 'o':
print('o won!')
return
if positions[2] == 'o' and positions[4] == 'o' and positions[6] == 'o':
print('o won!')
return
return
board()