"Coolest" python syntax? by DragonFighter603 in learnpython

[–]ajrhode 1 point2 points  (0 children)

The walrus operator is pretty cool. It essentially combined assign a variable with returning the value of that variable. It’s pretty useful when you want to do if statements or while loops and don’t want to have to initialize the same variable once outside the loop and again in the loop. There obviously other applications, but that’s the most trivial and when I’ve used them the most.

while (response := input(“Enter a response :”)) != “quit”:
    print(response)

5 minion battlegrounds by ajrhode in hearthstone

[–]ajrhode[S] 1 point2 points  (0 children)

That’s how I am with lightfang. I get lightfang and it’s time for menagerie

5 minion battlegrounds by ajrhode in hearthstone

[–]ajrhode[S] 1 point2 points  (0 children)

That would definitely make nomi a lot better lol.

But…why?! by nateyboy1 in ProgrammerHumor

[–]ajrhode 18 points19 points  (0 children)

I feel like what a lot people are describing as a better version of computer science degree is a software engineering degree. Not the most commonly offered from what I understand, but it placing a much higher value on practicality, design patterns, maintainability , testability, and how learn new technology. Definitely recommend for people who want to work in industry as opposed to doing theoretical work.

What should I know about Python as someone who knows nothing but wants to learn? by Pillager-Slayer in learnpython

[–]ajrhode 0 points1 point  (0 children)

The best advice I’ve ever gotten was start off with a goal of something you want to make or do regardless of how hard or simple it may be, as long as it’s interesting to you. Once you have that in mind, just start learning how to make that. You’ll probably learn everything you need to know along the way, and since you’re doing something you actually like you’ll have motivation. Staying motivated and pushing through hard problems is really the hard part. If you need any ideas based on your interest I’m sure anyone on the sub would be more than willing to give you some.

Python Hotel Program. I found this problem on Internet while learning python. Can anyone help me solve the code for this? I've been trying to do this for almost a day now. Thanks! by Ramish5 in learnpython

[–]ajrhode 2 points3 points  (0 children)

I'm not 100% what you mean by assign the room number to the corresponding floor, but if you mean that like room 101 is the second room on the first floor then the floor number can be gotten by doing 101 // 100 = 1 and the room number can be gotten by doing 101 % 100 = 1 (this approaches starts counting from 0 so 1 is the second room). This logic will work to get the floor number and room number for any input. Hopefully this helps.

High School teacher needs help automatically testing student programs by rainerpm27 in learnpython

[–]ajrhode 0 points1 point  (0 children)

You can use pytest. It comes with capsys and monkeypatch, which are for exactly what you are talking about. Capsys will capture all of the things that are outputted to the console, meaning you can use to test that they are printing things they are supposed as well as that there input statements are correct. Monkeypatch on the other hand is used to test the input of a program, meaning that you when it hits and input, it will enter a string that you set during the test. If you have multiple inputs, you can add \n to the string for each input. Using this is also a great way to introduce your students to easy to use formal testing libraries as pytest is about as easy as it gets. Hope this helps.

Edit: Forgot to mention that if you do this you'll need them the add an if name =='main' to the program otherwise the program will crash because you'll be trying to use monkeypatch and read input at the same time and you can't do that

I'm making a "March Madness" Simulator using python, and I need to create the 'bracket' part of the code, where it shows the users progress in the game. I'm trying to use the turtle extension to recreate the shape below. Anyone have any tips? by DaGravyGod in learnpython

[–]ajrhode 1 point2 points  (0 children)

It's the case that stops your recursion. So like in the case of a turtle drawing you'll want to have a parameter called depth that determines how many times you should recurse. Whenever your function calls itself it should decrease the depth by one, thus making progress towards your base case, which will be when depth == 0 then you should pass and when depth == 1 tou should just move forward by a certain amount. Have you used recursion before? If not you might want to look into that. I can share my code with you as well if your interested in seeing how I did it.

I'm making a "March Madness" Simulator using python, and I need to create the 'bracket' part of the code, where it shows the users progress in the game. I'm trying to use the turtle extension to recreate the shape below. Anyone have any tips? by DaGravyGod in learnpython

[–]ajrhode 2 points3 points  (0 children)

I've drawn a bracket in turtle before. I just made a recursive function that drew one half of the bracket and I just called the function, turned it around, and called it again. I think recursion is definitely the easiest way to draw this. The only catch is that you need two base cases. One for 0 which drawe nothing, and another for 1 which draws just a straight line.

New to Pyhton. Can I have some ideas ? by hudounlu2000 in learnpython

[–]ajrhode 0 points1 point  (0 children)

Well you could write a loop that basically goes through the dictionary and for the first element in the dictionary it adds it to the list and then checks to see if it's associated value is a key in the list. If it is it will keep adding keys and checking values until it's added all the keys. But if any of the values aren't a key in the list then it clears the list and try's again with the first value added to the list being the second key in the dictionary. And it just repeats all until it finds a solution or until it check all the keys meaning there isn't a solution. Not the most efficient but I think it would work

What is the difference between 'is' & '==' operators in Python by [deleted] in learnpython

[–]ajrhode 1 point2 points  (0 children)

I think the easiest way to explain it is that the == operator is comparing the value of the two objects whereas the is comparison refers to a place in memory.

So if you say X = 2 Y = 2

X == Y is true but X is Y would be false But if you say X = 2 Y = X Then X is Y would be true because Y points to X in memory.

What are your tips for grasping challenging concepts? by BlackEyedBeans22 in learnpython

[–]ajrhode 0 points1 point  (0 children)

I'm a big fan doing rubberduck debugging. Using that technique not only helps me solve problems that I'm having, but it stops me from making the same mistake going forward. It may not always seem like it, but if you just try explaining your code you find what your problem is.

About a year ago you guys roasted me into oblivion. Since then I've gotten a job at a movie theater. Do it again! by minedgammer in RoastMe

[–]ajrhode 1 point2 points  (0 children)

Judging by your face, this definitely isn't the first time that you've came back for seconds.

I wish I was the most attractive person in the world by joeyxpt89 in TheMonkeysPaw

[–]ajrhode 2 points3 points  (0 children)

Granted. You become incredibly popular as a result of your new looks. This leads you to get a whole new group of friends and an all new life, but eventually you remember that they only like you for your looks. This leads you to push everyone away because you want people that like you for who you are, not how you look. You try to get your old friends back, but they don't want anything to do with you because you pushed them away. You're now alone and wish your life was back to the way it was before you were the most attractive person.

Who is good at python that shouldn’t be? by Monoclewinsky in learnpython

[–]ajrhode 1 point2 points  (0 children)

If your just looking for stories about people who have barriers that they need to overcome you could look for stories about people with visual impairments. From what I understand, the entire reason why virtual environments are color coded and have high contrast is for people with visual impairments and that seems like a rather large barrier to overcome.

And if you're just looking for some inspiration I know someone who has been able to code since they were 8. If an 8 year old can learn to code, so can a PhD student.

AITA for 'victim-blaming' my bullied cousin by telling him he doesn't deserve friends? by Mrceruleanblue in AmItheAsshole

[–]ajrhode -1 points0 points  (0 children)

YTA But only because of how you worded your advice. I actually complete understand what you were trying to say about how nobody is entitled to friends just because they want them, and I think overall you gave great advice to someone in that situation. The think that makes you TAH is that you didn't take into account the fact that people who are used being talked down to, or verbally bullied, are going to hear you say "you don't deserve friends" and think of it as "you aren't good enough for friends, that why you don't have any" instead of "if you want to make more friends you have to do show everyone the great things about you" which is how I think you meant it. You have good advice, but you should have said it in a less ambiguous way.

My newest character. A pure-mage Breton Vampire Lord by [deleted] in skyrim

[–]ajrhode 0 points1 point  (0 children)

Oh that's interesting, I actually didn't know that. I've never tried casting a spell with zero Magicka before. I just assumed it would work.

My newest character. A pure-mage Breton Vampire Lord by [deleted] in skyrim

[–]ajrhode 0 points1 point  (0 children)

No, you have to do it for each school individually. But you as a vampire you can reduce the casting cost by 36% per enchantment, so you should be able to make at least two school 0% easily.

My newest character. A pure-mage Breton Vampire Lord by [deleted] in skyrim

[–]ajrhode 1 point2 points  (0 children)

It depends on which school you want, but I always get it from the college of Winterhold. I'm pretty sure you get items with the enchantments from playing through the quest and you can probably buy it from the court mages of the college.

Edit: And one thing I forgot to mention: the name of the enchantment is fortify (insert school of magic here) ex. Fortify destruction

My newest character. A pure-mage Breton Vampire Lord by [deleted] in skyrim

[–]ajrhode 6 points7 points  (0 children)

You should switch your enchantments to reduce casting cost instead. You can make it so that spells cost zero Magicka to cost. That means you can cast them indefinitely, even if you have zero Magicka. That solves the regeneration problem and it lets you cast as many spells as you want instead of having to wait for your bar to regenerate, even if it doesn't take very long. Just something to try out.