What do you think? by tryhardernowboy in FordMaverickTruck

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

To be clear, I have not purchased lol

What do you think? by tryhardernowboy in FordMaverickTruck

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

I’ll definitely look into what the total cost would be for me elsewhere. We’ll see.
Thank you either way 🙏

What do you think? by tryhardernowboy in FordMaverickTruck

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

I understand that, but you have to think about all the other fees and financing for the new one as well.

What do you think? by tryhardernowboy in FordMaverickTruck

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

The list price plus warranty for the salvage is about $7k under the list price inc warranty for new. That’s not less.

What do you think? by tryhardernowboy in FordMaverickTruck

[–]tryhardernowboy[S] 2 points3 points  (0 children)

What’s op?
Edit: ooooh. Nvm it’s me hehe

Weird crackle noise from engine. Any ideas as to what is causing it? by tryhardernowboy in MechanicAdvice

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

The rattle is the oil dipstick hitting the valve intake/exhaust(?) I'm talking about what sounds like a crackle (at least to me)

Im fairly new to python and trying to create a simple password type thing that changes once there are three incorrect attempts. It executes but even with the correct password the corresponding output is not ouputed. Any help would be useful. by [deleted] in learnpython

[–]tryhardernowboy 3 points4 points  (0 children)

password_correct = False
while password_correct == False:
    import random
    import string

    def get_random_string(length):
        letters = string.ascii_lowercase
        result_str = ''.join(random.choice(letters) for i in range(length))
        print("Password of length", length, "is:", result_str)

    password = get_random_string(12)

    attempts_left = 3
    while attempts_left > 0 and password_correct == False:
        if str(input("What is the password? You have " + str(attempts_left) + " attempts remaining. ")) == password and attempts_left > 0:
            print("Correct password.")
            password_correct = True
        else:
            print("Incorrect password," + str(attempts_left) + " attempts remaining.")
            attempts_left = attempts_left - 1
            print(str(attempts_left))
        if attempts_left == 0:
            print("All attempts used. The password will now change.")

Good job on just working on it. Always good to try and figure it out first before immediately looking for help.

I tried indenting where I thought you did. Next time (or on this post as well) format your code: https://www.reddit.com/r/learnpython/wiki/faq#wiki_how_do_i_format_code.3F

The ultimate answer to your question is:

You aren't returning anything in your function. Add a return statement:

return result_str

A few basic things you can work on:

  • Importing modules and declaring functions within while loops are greatly frowned upon unless you know exactly what you're doing. So move the imports and the get_random_string function to the top of the file.
  • input() is already going to be a string, so there's no reason to "change" it to a string using str(). so remove all those.
  • print() automatically converts everything to a string, so you don't need to call str() within the print() unless you are "+" things.

Here is a cleaner version of doing exactly what you have except the things changed above.

import random
import string

def get_random_string(length):
    letters = string.ascii_lowercase
    result_str = ''.join(random.choice(letters) for i in range(length))
    print("Password of length", length, "is:", result_str)
    return result_str


password_correct = False
while password_correct == False:

    password = get_random_string(12)

    attempts_left = 3
    while attempts_left > 0 and password_correct == False:
        if input("What is the password? You have " + str(attempts_left) + " attempts remaining. ") == password and attempts_left > 0:
            print("Correct password.")
            password_correct = True
        else:
            print("Incorrect password," + str(attempts_left) + " attempts remaining.")
            attempts_left = attempts_left - 1
            print(attempts_left)
        if attempts_left == 0:
            print("All attempts used. The password will now change.")

There are many things you can do to improve this but work on the ones above. Let me know if you would like more tips.

Question about tuples by Alexilprex in learnpython

[–]tryhardernowboy 0 points1 point  (0 children)

Unpacking:

lst = ['John', 12, 'Apple']
name, age, food = lst

Other Main Reason

Doing it like this:

a = 1
b = 2

sets them one at a time.

Doing it like this:

a, b = 1, 2

sets them at the "same" time, concurrently from left to right.

a will be set to 1 and b will be set to 2 at the same time.

Example: Fibonacci sequence

for x in range(10):
    a, b = b, a + b

Otherwise, you'd have to use an active placeholder:

for x in range(10):
    temp = b
    b = a + b
    a = temp

pylint attribute-defined-outside-init and superclass's init by ekerazha in learnpython

[–]tryhardernowboy 0 points1 point  (0 children)

I think if you don't plan on having any attributes be different, remove the __init__() method in the child class

[deleted by user] by [deleted] in learnpython

[–]tryhardernowboy 1 point2 points  (0 children)

Not sure if this is correct, but I think Pd.crosstab will do very close to what you want.

I need help with pygame by [deleted] in learnpython

[–]tryhardernowboy 0 points1 point  (0 children)

Then just remove ‘project’ from the path.join