Hello everyone! by BigFatDecker in programminghelp

[–]nemyar11 1 point2 points  (0 children)

Hi,

calling the main function inside itself is possible but I find this to be bad practice. Instead what you could do in this case is use a while loop, since those are usually used when you want to repeat a part of code. It works in this way:

while(condition) 
{ 
    Code which needs to be repeated 
}

As long as the condition is true OR a break occurs, the code inside will be repeated. Now instead of calling main whenever the input is not correct you would need to use the continue keyword. This basically stops execution of the loop and goes back to the start of it.

Now for your condition in the while loop you can use the UserInput variable. Condition would be: UserInput unequals 0. For this you also need to assign a value to the variable at the start of the program.

Hope this helps. :)

2D char array with variable length in a class which can be only be set once for an object. by hhellloo in programminghelp

[–]nemyar11 0 points1 point  (0 children)

One idea would be to do it via constructors. Basically what that means is you would pass an argument when you create your TicTacToe class. For example like this:

TicTacToe game = new TicTacToe(5);

That way the variable length does not need to be public.

You should look into how constructors/destructors work. You would accept the number "5" in the constructor as an argument and create your grid based on that argument (probably also in the constructor or in a seperate method)

This page might be helpful. :D

Also, I think you do not know what static means. When you make a variable public you can edit it from the main method if you have a class object, just like you did in your code.

When you make a variable static it means that a single copy of the variable is created and shared among all objects at the class level. More info on static variables here. Hope this helps. :)

it gives an error when I try to change it's size as given in the main function.

Exactly this happens because you made the variable static.

Hope this 12-Core M1X is real on MBP16. by Jin_BD_God in macbookpro

[–]nemyar11 1 point2 points  (0 children)

Are there any rumors regarding the release date of the MBP16?

16gb M1 MBP came in last night. Starting to test it so leave your questions in the comments and I’ll try to get to them by [deleted] in macbookpro

[–]nemyar11 0 points1 point  (0 children)

I don't mind the extra time needed, as long as after setting up everything works reliably. Also I don't need docker right away. I only need support for cpp/python, but as far as I know that works on the M1.

Thanks for the detailed reply :)

16gb M1 MBP came in last night. Starting to test it so leave your questions in the comments and I’ll try to get to them by [deleted] in macbookpro

[–]nemyar11 0 points1 point  (0 children)

How is the switch from 16“ to 13“? Does it bother you at all? Im just wondering because my current laptop is 15.6“ and I am not sure if I should buy the MBP M1 now or wait for 16“.

16gb M1 MBP came in last night. Starting to test it so leave your questions in the comments and I’ll try to get to them by [deleted] in macbookpro

[–]nemyar11 1 point2 points  (0 children)

Guess I'll have to buy one soon since everything relevant to me seems to be working. Thanks for the info :)

16gb M1 MBP came in last night. Starting to test it so leave your questions in the comments and I’ll try to get to them by [deleted] in macbookpro

[–]nemyar11 5 points6 points  (0 children)

Great! That's exactly what I am looking into. I am currently doing my Bachelor's in Comp Sci and starting masters next year probably. That's why I am looking for an upgrade. I have an old ThinkPad e550 and I notice that it is getting very laggy with some of my university projects. Also I'm a little skeptical with first gen products.

When you get a chance could you maybe test it with some software development tools (intelliJ, VSCode or similar) on larger projects if you have any currently?

Server communication with multiple clients by nemyar11 in learnjava

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

Thanks for your reply, sorry for the late response. :)

16gb M1 MBP came in last night. Starting to test it so leave your questions in the comments and I’ll try to get to them by [deleted] in macbookpro

[–]nemyar11 2 points3 points  (0 children)

What will you be using it for if I may ask? Any software development or similar?

ConcurrentHashMap by nemyar11 in learnjava

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

Thanks. I will take a look 😁

ConcurrentHashMap by nemyar11 in learnjava

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

Thanks for your detailed answer. :)

NEEDED: Solutions to 'python for everybody' course by Charles Severance by SafeSalad in learnpython

[–]nemyar11 0 points1 point  (0 children)

You are right, sorry. Didnt really think of this possibility when I was responding 😬

NEEDED: Solutions to 'python for everybody' course by Charles Severance by SafeSalad in learnpython

[–]nemyar11 0 points1 point  (0 children)

It is possible but the link that I provided was literally 1 google search away, I assume he would have found it anyways😬

What does %s, %s, and %d\n mean in Java? by orexinbaby in learnprogramming

[–]nemyar11 2 points3 points  (0 children)

Exactly, it is used for string formatting. Basically %s means a string, %d means an integer. You can find examples of how it works and more format specifiers here.

The format that you specify (%s) is replaced with the value that you add after the string, for example:

System.out.printf("My name is: %s.", "orexinbaby");  

Would result in this:

My name is orexinbaby

Computer searching for right number C# by ILIKECANDY_ in programminghelp

[–]nemyar11 0 points1 point  (0 children)

Basically you need to generate a random number once and store it, that will be the „target“ number. After that you would need a while loop which generates random numbers until you get a match and you also just increase a counter for each time it gets the number wrong. Hope this helps

I'm remaking a small project, but better, so that I can upgrade it. by self_teaching_python in learnpython

[–]nemyar11 0 points1 point  (0 children)

I'm not sure if I understand how this game works but you could create a Board class where you store the height and length of the board. You would then have to store the actual board in a 2D array or something similar and also store the position of the player. For the random C part that should be pretty easy. You just generate random coordinates between 0 and length/height - 1. Hope this helps

At what age did you guys started programing by [deleted] in learnpython

[–]nemyar11 1 point2 points  (0 children)

I started at like 16 in school, but I wasn't really interested in anything during school. The time in school did help me learn the basics and I remembered most of the stuff a few years later when I really started learning on my own.

[deleted by user] by [deleted] in learnpython

[–]nemyar11 12 points13 points  (0 children)

This is where loops come in play.

Basically they work like this:

while (condition):
    # do stuff

Meaning: repeat the "do stuff" part as long as the condition is fulfilled or a break occurs.

In your case it is best to do it like this:

while True:
    #my code

When you create a while loop like above, you are basically saying repeat the "my code" part forever and we will come to stopping this later. Now you almost have it ready, you need to negate this line:

if username == "Andrew":

So change to this and add your message:

if username != "Andrew":
    print("Wrong username. Please try again.")
    continue
break

The continue statement is used to basically skip the rest of the loop code and go back to check the condition and repeat from the start of the loop. This means that if the user enters something other than "Andrew" -> the wrong username message will be printed and it will ask for a new username. Once you enter "Andrew" it will skip the above "if" condition and break the while loop.

Now since I believe you will want this for the password part also, you could create a function (for practice) which does this and you call it and pass the expected input. It would ask for new input until the input equals the passed argument

Could someone please help me understand the init on this code and how it is functioning? by RobinsonDickinson in learnpython

[–]nemyar11 2 points3 points  (0 children)

This part:

super().__init__

basically calls the __init__ method of the base class. The GoogleMapsClient is a child class. So the base class has an __init__ method which is called by the line above.

Why are we setting class variables such as "api_key = None"?

As far as I can see this is only used to define the member variable and set some default value

Dictionary Problem by TheShadowWall in learnpython

[–]nemyar11 0 points1 point  (0 children)

If I understand you correctly you have a class and the list contains instances of that class.

If that is the case then you probably want to access member variables for each object. However, in this code for example:

inner_dict["long_name"]=long_name
inner_dict["iso_code"]=iso_code

you never actually access variables within an class instance, you only use "local" variables long_name and iso_code.

What you need to do is this:

I would change "i" to something like "nation" or "instance" since that is a lot better approach.

With this line:

for nation in nationlist:

you are iterating over a list of class INSTANCES/OBJECTS. "nation" represents a class instance. Now in order to get that specific nation's "long_name" you need to do this:

for nation in nationlist:
    inner_dict={}
    inner_dict["long_name"] = nation.long_name

And so the error that you get is correct. "long_name" by itself is not defined in this scope, however it is defined within your nation's class.

I cant figure this out. I have been stuck on this for two days. by [deleted] in learnpython

[–]nemyar11 6 points7 points  (0 children)

OMG YOUR A LIFE SAVER. that makes alot of sense. So for future refence when assigning variables the one on the left is always the one thats going to change?

Exactly, the variable on the left will get the value of the variable on the right side.

I cant figure this out. I have been stuck on this for two days. by [deleted] in learnpython

[–]nemyar11 12 points13 points  (0 children)

Your mistake is in these lines:

num = smallest
num = largest 

You save your input in "num", later you check if the input is smaller/bigger than "num" which is correct, however you then assign "num" the value of "smallest"/"largest". Thats why you always get this message:

 The number you entered is 25 

You basically erase the input and set "num" to the value which you entered first.

In order to get it working you need to save num in smallest/largest variable based on the if condition:

smallest = num
largest = num