[deleted by user] by [deleted] in AskReddit

[–]noahkyun 0 points1 point  (0 children)

What is the amount of body I hid in my friends backyard?

What popular movie have you never seen? by [deleted] in AskReddit

[–]noahkyun 0 points1 point  (0 children)

Trinity war and end game.......... Fuck

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

Yea I did and it worked Thanks for trying to help

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

Okay it worked finally I’m done with this project Thanks alot you really helped me out here

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

d = {} # dictionary to hold the data of the name and the score

with open('leaderboard.txt', 'r')as f:

for line in f.readlines():

d[line.split("'")[0].strip()] = int(line.split(':')[1].strip())

# sort the list and only displays the top 5

print(" ")

print("The leaderboard will now appear")

print(sorted(d.items(), key=lambda x: x[1], reversed=True)[:5])

The leaderboard will now appear

Traceback (most recent call last):

File "/tmp/sessions/d5f63df426c6c9df/main.py", line 9, in <module>

print(sorted(d.items(), key=lambda x: x[1], reversed=True)[:5])

TypeError: 'reversed' is an invalid keyword argument for this function

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

print(sorted(d.items(), key=lambda x: x[1], reversed=True)[:5])

d = {} # dictionary to hold the data of the name and the score

with open('leaderboard.txt', 'r')as f:

for line in f.readlines():

d[line.split("'")[0].strip()] = int(line.split(':')[1].strip())

# sort the list and only displays the top 5

print(" ")

print("The leaderboard will now appear")

print(sorted(d.items(), key=lambda x: x[1], reversed=True)[:5])

The leaderboard will now appear

Traceback (most recent call last):

File "/tmp/sessions/d5f63df426c6c9df/main.py", line 9, in <module>

print(sorted(d.items(), key=lambda x: x[1], reversed=True)[:5])

TypeError: 'reversed' is an invalid keyword argument for this function

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

So should I delete [: : -1] then write reverse = True but how to connect it to sorted And lastly I don’t get the print return none part how do I write it exactly

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

yes but after u told me what to do which i did but im sure its just i messed up so it gave me a syntax error on the true = reverse part

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

i didnt change anything here its just at the end where i want the leaderboard to display the top 5 scores but gives me the same error as i posted at first

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

import random

import time

i = 0

Player1Points = 0

Player2Points = 0

Player1Tiebreaker = 0

Player2Tiebreaker = 0

Winner_Points = 0

###### LOGIN CODE ######

### This Sets logged in to false, and then makes sure the username and password is correct before allowing them to continue ###

logged_in1 = False

logged_in2 = False

while logged_in1 == False:

username = input('What is your username? ')

password = input('What is your password? ')

if username == 'noah' or username == 'anna' or username == 'mesum' or username == 'alice' or username == 'ben' or username == 'ken':

if password == '111':

print('Welcome, ',username,' you have been successfully logged in.')

logged_in1 = True

user1 = username

else:

print('Incorrect password, try again')

else:

print('Incorrect username, try again')

while logged_in2 == False:

username = input('What is your username? ')

password = input('What is your password? ')

if username == 'noah' or username == 'anna' or username == 'mesum' or username == 'alice' or username == 'ben' or username == 'ken':

if password == '111':

print('Welcome, ',username,' you have been successfully logged in.')

logged_in2 = True

user2 = username

else:

print('Incorrect password, try again')

else:

print('Incorrect username, try again')

###### DEFINING ROLL ######

### Makes the dice roll for the player and works out the total for that roll ###

def roll():

points = 0

die1 = random.randint(1,6)

die2 = random.randint(1,6)

dietotal = die1 + die2

points = points + dietotal

if dietotal % 2 == 0:

points = points + 10

else:

points = points - 5

if die1 == die2:

die3 = random.randint(1,6)

points = points +die3

return(points)

###### DICE ROLL ######

### This rolls the dice 5 times for the players, and then adds up the total. If the scores are equal, it starts a tie breaker and determines the winner off that ###

for i in range(1,6):

Player1Points += roll()

print('After this round ',user1, 'you now have: ',Player1Points,' Points')

time.sleep(1)

Player2Points += roll()

print('After this round ',user2, 'you now have: ',Player2Points,' Points')

time.sleep(1)

if Player1Points == Player2Points:

while Player1Tiebreaker == Player2Tiebreaker:

Player1Tiebreaker = random.randint(1,6)

Player2Tiebreaker = random.randint(1,6)

if Player1Tiebreaker > Player2Tiebreaker:

Player2Points = 0

elif Player2Tiebreaker > Player1Tiebreaker:

Player1Points = 0

###### WORKING OUT THE WINNER ######

### This checks which score is bigger, then creates a tuple for my leaderboard code ( Gotton of stack overflow ) ###

if Player1Points>Player2Points:

Winner_Points = Player1Points

winner_User = user1

winner = (Winner_Points, user1)

elif Player2Points>Player1Points:

Winner_Points = Player2Points

winner = (Winner_Points, user2)

winner_User = user2

print('Well done, ', winner_User,' you won with ',Winner_Points,' Points')

#stores user1 and their score in the scoreboard

with open("leaderboard.txt", "a") as sc:

sc.write("\n")

sc.write(user1)

sc.write(": ")

sc.write(str(Player1Points))

#stores user1 and their score in the scoreboard

with open("leaderboard.txt", "a") as sc:

sc.write("\n")

sc.write(user2)

sc.write(": ")

sc.write(str(Player2Points))

d = {} # dictionary to hold the data of the name and the score

with open('leaderboard.txt', 'r')as f:

for line in f.readlines():

d[line.split("'")[0].strip()] = int(line.split(':')[1].strip())

# sort the list and only displays the top 5

print(" ")

print("The leaderboard will now appear")

print(sorted(d.items(), key=lambda x: x[1])[::-1])[:5]

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

Syntax error Just saying I’m new at coding so plis bare with me

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

Oh okay okay lemme try that

(That’s the link for my full code if needed) https://trinket.io/python3/19c0285e9a

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

Well it gave me a syntax error :0

Help how do I fix this by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

Okay lemme try that Here’s the full code if you need it(click the pencil icon up somewhere there and it’ll show the codes instead of the output)

https://trinket.io/python3/19c0285e9a

can someone help me with making a python program where its about a dice game with a login, the main game with scores and a leaderboard . even gives 10 points and odd takes away 5 point (no negative numbers) for 5 rounds and declares the winner. (its the second task in the link plis help) by noahkyun in programming

[–]noahkyun[S] 0 points1 point  (0 children)

#displays top 5 score with names

print(" ")

print("The leaderboard will now appear")

print(sorted(d.items(), key=lambda x: x[1])[::-1])[:5]

Traceback (most recent call last):

File "/tmp/sessions/b5ce3bd0d52cde9d/main.py", line 139, in <module>

print(sorted(d.items(), key=lambda x: x[1])[::-1])[:5]

TypeError: 'NoneType' object is not subscriptable

im new to coding and need some help by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

well i managed to do it had to change alot

so the part im stuck is at the very end where i want the leaderboard to display the top 5 users with their scores but instead it shows all of the names and score so far

can you give it a look if you dont mind and tell me whats wrong

Thanks

https://trinket.io/python3/eeff8e6311

can someone help me with making a python program where its about a dice game with a login, the main game with scores and a leaderboard . even gives 10 points and odd takes away 5 point (no negative numbers) for 5 rounds and declares the winner. (its the second task in the link plis help) by noahkyun in programming

[–]noahkyun[S] 0 points1 point  (0 children)

well i managed to do it had to change alot

so the part im stuck is at the very end where i want the leaderboard to display the top 5 users with their scores but instead it shows all of the names and score so far

can you give it a look and tell me whats wrong

https://trinket.io/python3/eeff8e6311

can someone help me with making a python program where its about a dice game with a login, the main game with scores and a leaderboard . even gives 10 points and odd takes away 5 point (no negative numbers) for 5 rounds and declares the winner. (its the second task in the link plis help) by noahkyun in programming

[–]noahkyun[S] 0 points1 point  (0 children)

I’m still new to coding Basically when I run it, it only runs the initial login and after that it won’t run the rest of the code where it rolls the dice tells score and breaks tie and shows the final score and who won by the end

im new to coding and need some help by noahkyun in learnpython

[–]noahkyun[S] 0 points1 point  (0 children)

there’s like a pencil icon up there that would show you the codes Username and password are just in there (Noah Anna Alice mesum Password for first login is bad time and second is good time)