Return to Level1Techs.com

Devember - Relearning to program using Python

devember2k18

#61

Day 17

Thanks! I tired to figure out that problem on my lunch break at work today, but it didn’t work. I have a feeling the problem is my string is a variable, and that variable is the one that by default adds white space after it. I have to do more research tomorrow.

I did get the random generator to work, so some progress at least. Well, three lines of code… :expressionless:


#62

print(‘Hello’, name + “, how are you doing?”)

String Concatenation!
image


#63

That is strange, it puts a space inbetween elements…

print ( **objects* , *sep=' '* , *end='\n'* , *file=sys.stdout* , *flush=False* )

Print *objects* to the text stream *file* , separated by *sep* and followed by *end* . *sep* , *end* , *file* and *flush* , if present, must be given as keyword arguments.

Ah there you go, it has a bunch of default attributes. You could override these.


#64

I have no idea what you just said @ArgGrr XD…

Anyways, I should also mention that the .format() works like this:
print("Hello {name}, how are you doing?".format(name = 'Bob'))
or like this:
print("Hello {}, how are you doing?".format('Bob'))

Keep in mind this is a newer method of doing the traditional %s, %d, etc. For example:
print("Hello %s, how are you doing?" % ('Bob'))

They should all result in:
Hello Bob, how are you doing?


#65

I pulled that from the python documentation.

It is the description of the print function. It explains where there is a space between the elements, because of the default separator, sep=’ '.
I assume the ** means it is an optional parameter, with a default value which takes effect if not specified.

So you can do this:

name = "ArgGrr"
print('Hello ', name, ", how are you doing?",sep="")

Hello ArgGrr, how are you doing?

Or to be annoying:

name = "ArgGrr"
print('Hello', name, ",","how","are","you","doing?",sep=" :ghost:")

Which yeields:
Hello :ghost:ArgGrr :ghost:, :ghost:how :ghost:are :ghost:you :ghost:doing?

I guess it comes down to what the function is designed to do. Dump a bunch of information into a file in a safe sort of fashion. i.e. make something readable.
The format stuff is probably a good idea, so you can build up a string and then print that, instead of using the print command to build the output.


#66

That makes so much sense! I was thinking you were printing those things out so I got really confused XD. Tried it in IDLE and was like “wuuuttt???”


#67

Day 18

Thanks @Erzor and @ArgGrr!

name = ('James')
print('Hello {}, how are you doing?'.format(name))
print('Hello', name + ', how are you doing?')

These both give me the exact result I wanted!

I also got the fighting mechanism to work. It simulates a dice roll, and yes, it is atm quite unfair. :smiley:


#68

Yeah that’s my bad for not putting in some context!
I guess the point I was trying to make is there is usually a reason for things like this, and once you get familiar enough with with the framework you can dive into the documentation to find out why.
Find out the proper definition and use of functions and all that good stuff.

And finally, if you can’t find the reason, search on stackoverflow or something else, it might be a bug in the framework.


#69

Day 19

Today I tried to create nested loop for asking if player want’s to fight again or not. I’ve run out of time for today so let’s see what I can do tomorrow.

What I’m trying to do is this: First the player will fight an enemy, whether he wants or not. Next the game asks if player would like to fight again? I’m thinking maybe I should create a class or a method for the fighting part, and then I could first call the method once, without “yes/no” questions. After the first fight the game could present the “yes/no” question and if the answer is yes, the fighting method is called again inside this new “yes/no” loop. The loop then repeats until player will answer “no”.

I’m actually not looking for advice yet, I’m just writing my thoughts down so that I remember where to continue. :smiley:

Changes pushed to my repo. See ya tomorrow!


#70

Day 20

Managed to use maybe 15-20 minutes of my time for Devember today. Tomorrow will be a travel day for me so I spent most of my free time today packing stuff and loading my car ready. I’ll spend Christmas with my family, and my parents live on the country side with little erratic internet connection. So I try to put some work everyday towards this during Christmas holidays, but no promises. I will at least update my Devember repository if I get something done.


#71

Good luck over Xmas! I’ll keep an eye on the repository, keen to see a game! Or anything really.


#72

Day 21-22

Yesterday I didn’t do anything for devember, but today I had free time. I have my MacBook with me and I’m using it for coding during the Christmas holidays. Installed Pycharm and tried to continue the game.py script, but now it looks like nothing is working. At first I thought I’m once again doing something wrong, but since my earlier test scripts don’t work either I realized Mac only has Python 2 installed out of the box. Tried to install Python 3 but for that it looks like I need Xcode, and installing Xcode with slow mobile internet… Well, I’ll continue tomorrow. :smiley:


#73

Day 23

Got Python 3 installed to my MacBook. Spend probably over 2 hours today figuring out things. I finally got the yes/no loop to work, meaning game will now make the player fight once, and then ask if player woud like to fight again or not. I commented the yes/no loop out from the main game.py script, since I tried to merge that functionality to the fighting method. That method already rolls the dice and thus determines if you won the fight or not, but now I would also like to put the yes/no loop into that same method, or class.

IDK, I’ll try to find time tomorrow to figure this out. I think I probably have to put that yes/no loop to separate method. Reason I want to do this is to modularize (is that a word? :smiley: ) my code so that I can then do all kinds of funky stuff with the modules without worrying my whole script will break because of it. And also to be able to recycle my code. I’m lazy and don’t want to write things multiple times. :grin:


#74

Day 24

Well I admitted in Devember thread I slacked today, but I’m actually now browsing some python documenttion. I won’t be able to spend one hour for this today, though.

I did do someting unrelated to this project though:

And last but not least: MERRY CHRISTMAS! :slight_smile:


#75

Day 25-26

I skipped yesterday and decided to spend some time with my family and especially my dad. So no devember activities to report on 25th.

Today was again a traveling day for me, but after I came home I spend some time reading documentation and figuring out where I am right now with my project and what I still need to do. Nested loops etc are still giving me a head ache, so I’m thinking I should probably spend tomorrow reading and testing how loops work. I don’t know why but for me the loops were much easier to work and understand in Java. I’ve been now coding almost a month with python and the indentation still confuses me. IDK, maybe I’m just simple minded. :smiley:

Cya tomorrow.


#76

Day 27

Had quite busy day at work today and ended up working quite late, so I didn’t mange to put full hour for devember. I did play around with gmodule.py file, but eventually I put everything back to where I started. IDK, I feel I’m so close of getting that yes/no question loop to work together with the fighting mechanism, but still it feels like the solution is so far away. Extremely annoying. :smiley:

Tomorrow I hopefully have some actual code to share.


#77

Day 28 (yesterday)

Well, yesterday was also a busy day at work, and in addition I had some real life stuff to take care of. So once I finally got home I didn’t have the energy to start anything that would require actual brain power.

Today is a new day so I’ll get to work. fires up Pycharm and opens a can of monster


#78

Day 29

Heeyyyy the yes/no option now works from the separate class! Created new battle() -class to gmodule.py -file, and separated the fighting mechanism and yes/no option to two different methods. I didn’t even google any help, just thought I try that and was pleasantly surprised it worked.

Another thing I did today was namegen() method. Purpose for this will be revealed later. :slight_smile: This method randomly picks up lowercase letters and some numbers, and then combines them to one variable that can be returned. I had trouble getting this method to work, since combining the letters and numbers didn’t work. I soon realized what I was trying was to perform a sum calculation with the variables, which ofc didn’t work because some of my variables are strings, not integers. Everything worked once I changed this:

abc = let1 + num1 + "-" + num2 + let2 + let3

to this:

abc = str(let1) + str(num1) + "-" + str(num2) + str(let2) + str(let3)

Or at least the output is now what I want it to be. :smile:

Changes pushed to repo, cya tomorrow!


#79

Day 30

Today I spend most of my time thinking what I should do next, what functions I want to include to this game etc. I think the leveling up mechanism might be useless for this particular game, but I might include that even if it ends up being useless of unnecessary. I want to try to get it to work, if nothing else then it will be good learning experience.

I started to make the title menu for the game, but I ran out of time for today, so I’ll continue on that tomorrow.


#80

Day 31

Today I played around with the title menu and got it working (kind of). Made the same mistake like I did earlier, and tired to use integers as options when input reads the user input as string. Or that’s what I believe is happening. :thinking:


Whoo! I made it through the Devember! I was afraid if I’d be able to keep myself motivated whole month, but it turns out I did. The devlog and peer pressure certainly helped with that. :smiley:

I probably won’t be updating this devlog daily anymore, especially since at least half of my updates this far have been “idk what’s happening, nothing works!!”, and I don’t see any point in those updates.

I will keep working on this. What I still want to do:

  • Implement some kind of leveling functionality
  • Maybe implement some kind of currency system (ability to buy and sell stuff?)
  • Include short story, with at least two possible endings.

The currency system will most likely end up being completely useless like the leveling system. Since I’m trying to follow (at least a little) the old programming assignment from my university course, I want to try and code those as a learning experience. And maybe I can reuse my code and try to make more advanced text game later?

Anyway, I will post updates here if/when there is any. Just no daily updates anymore.

Huge thanks to everyone who have showed interest towards my devember project, whether it been posting comments or just lurking. :slight_smile:

Happy new year to everyone!