jedesa> hey
jedesa: kin kon kan kon amigojapan Haniibooru
amgigojapan: hey jedesa !
amgigojapan: jedesa: one sec
amgigojapan: lol jedesa , that was funny
amgigojapan: jedesa: shall we start?
jedesa: ok amigojapan
jedesa: what are we learning today?
amgigojapan: jedesa: well, let me look at my notes
amgigojapan: jedesa: programming lessons, next up operator priority, string handling, classes, recursion
amgigojapan: jedesa: form easiest to hardest order
amgigojapan: jedesa: I think recursion can take up a whole lesson on its own
amgigojapan: and we may need to borrow some form my Think Like a computer lessons for it
jedesa: hmm
amgigojapan: jedesa: ok, so are you ready?
jedesa: what's a Think Like a computer?
jedesa: a youtube channel?
amgigojapan: jedesa: it is a board game I am making to teach programming, I had not told you about it yet
amgigojapan: jedesa: I have not published it yet
amgigojapan: jedesa: its nto finished
jedesa: Oh okay
jedesa: by the way
amgigojapan: yes?
jedesa: I have spend a little of time glossing over some fundamental programming concepts
jedesa: hopefully I could follow without much trouble
amgigojapan: ok, do you know what operators are? and what their priority is?
jedesa: hmm, symbols like +, -, AND, OR .. ?
amgigojapan: yes
amgigojapan: do you know the priority?
amgigojapan: jedesa: like if you do 2*2+1 whats is the difference between that and 1+2*2?
jedesa: not really, for any specific language
amgigojapan: jedesa: this is generally the same in every language
jedesa: I mean for arithmetic * takes precedence
amgigojapan: yes ok, yes
amgigojapan: then you know it
amgigojapan: jedesa: did you know that you can surround the operations in parenthesis to change the priority?
jedesa: yes
jedesa: so like
amgigojapan: ah ok, let me mention it for the other people that may be seeing the lesson later
amgigojapan: like say 1+(2*2) is the same as 2*2+1
jedesa: yeah, I should like to know what you know too
amgigojapan: well, thats it for operator priority, if you are eve in doubt, just surrounding it by parenthesis so you know what goes first
jedesa: Okay
amgigojapan: jedesa: ok, so I guess we can go on ot string handling
amgigojapan: jedesa: so a string is something like str="abc"
amgigojapan: jedesa: in python if you want to "concatenate"(connect two stings) a string one way to do it, it to use the + sing, like this str = "abc" + "def"
jedesa: I see
amgigojapan: jedesa: you can do it inside a print statement too like this print("hello " + name)
amgigojapan: jedesa: name being a string variable
amgigojapan: jedesa: why don't you make a small exercise, getting input form the user asking him his name, and outputting hello and then their name?
jedesa: Yeah, okay
amgigojapan: :)
amgigojapan: then link me the code
jedesa: print("what is your name?") name=str(input()) print("hello " + name + "!") amgigojapan: let me see
amgigojapan: perfect jedesa !
jedesa: yay!
amgigojapan: jedesa: thats how i greet people on the BBS
amgigojapan: jedesa: now, look at the following code:
main_string = "Hello, world!"
substring = "world"
if substring in main_string:
print(f'"{substring}" was found in the string.') # Output: "world" was found in the string.
else:
print(f'"{substring}" was not found.')
jedesa: I see
amgigojapan: yeah
amgigojapan: so that is how you can verify if a substring , a string is found inside another string
jedesa: so string is made of bunch of characters, with that you can add or subtract it as well
amgigojapan: jedesa: then in python you have str.find() to find a substring position in a string, this is quite useful, because I will teach you how to use the position soon
jedesa: Okay
amgigojapan: jedesa:no, this is separate form the lesson of operators, string is only a bunch of characters
amgigojapan: adding a string to another string in python is called "concatenation" and in python it happens to be + that does it, but ti is not math
amgigojapan: like in PHP concatenation is done by using . not +
jedesa: hmm I see
amgigojapan: so in PHP you would do $str = "abc" . "def";
amgigojapan: yeah
amgigojapan: but lets worry about PHP later
amgigojapan: jedesa: in python and JS it is + in LUA it is .. and in PHP it is .
amgigojapan: but they are still similar
jedesa: . .. + are all operators in their respective language
amgigojapan: yes jedesa
amgigojapan: jedesa: now try this code:
text = "Hello, world!"
position = text.find("world")
print(position) # Output: 7
jedesa: Okay
jedesa: so 7 is from the length of "Hello, "
amgigojapan: jedesa: now this is very useful, cause if we know the position of a substring in a string we can do many operations on it
jedesa: do we have some examples?
jedesa: I don't feel any ideas for now
amgigojapan: yes exactly! jedesa now try a small exercise and show me if you can make a program that finds out if someone's name contains the letter a
amgigojapan: jedesa: and if it does, let me know which position of the word it is in
amgigojapan: jedesa: ok, I will make an example meantime
jedesa: # https://www.programiz.com/online-compiler/3zEZ7Dtxl2FHy
substr="a" print(f'"what is your name?"') name=str(input()) print(f'"{substr}" is at position {name.find(substr)}') amgigojapan: jedesa: it is useful cause for example:
text = "I love Python" new_text = text[:2] + text[7:] print(new_text) #output is "I Python" amgigojapan: will remove the world love form that new variable
amgigojapan: let me see
amgigojapan: ok that works jedesa , although notice if the name does not contain a, it will return -1
amgigojapan: which means "it was not found"
jedesa: Yes
jedesa: It could be added for handling non-existing word
amgigojapan: jedesa: now, make a program that takes input form the user for a string1, then and input form the user for a string2, and deletes the word form the string and prints the result
amgigojapan: yup
amgigojapan: take your time
jedesa: hmm?
amgigojapan: any questions?
jedesa: delete a substring in string1, based on input of string2?
amgigojapan: yes
amgigojapan: jedesa: oh I forgot to teach you a necessary component for that program
jedesa: actually let me try
amgigojapan: jedesa: len(string) gives you the length of a string
amgigojapan: do you need a hint?
jedesa: # https://www.programiz.com/online-compiler/2HhtjMY99LFzU
print("input string1") string1 = str(input()) print("input string2") string2 = str(input()) pos = string1.find(string2) while pos > -1: string1 = string1[:pos] + string1[pos+len(string2):] pos = string1.find(string2) print(string1) amgigojapan: let me see
jedesa: This should do it
amgigojapan: yeah it works! jedesa :) great!
amgigojapan: jedesa: now make a program that takes 3 strings, similar to this program, but now the third string should take the place of the word that was deleted
jedesa: Okay
# https://www.programiz.com/online-compiler/31ZQbvUMBRE3C
print("input string1:") string1 = str(input()) print("input string2:") string2 = str(input()) print("input string3:") string3 = str(input()) pos = string1.find(string2) while pos > -1: string1 = string1[:pos] + string3 + string1[pos+len(string2):] pos = string1.find(string2) print(string1) #example output input string1: HELLO WORLD BYE input string2: WORLD input string3: MARS HELLO MARS BYE jedesa: wow, fast
amgigojapan: let me see
amgigojapan: nice jedesa !
amgigojapan: jedesa: I think you have the basics of string handling now :)
jedesa: print("ehehe")
amgigojapan: :) amgigojapan: jedesa: I could give you a hard homework on string handling, if you want
jedesa: alright
jedesa: hold on
jedesa: we still have classes and recursion
jedesa: hmm okay
amgigojapan: jedesa: ok, don't do it now, it will take too long, but homework is, make the hangman game, using string handling
jedesa: I see
amgigojapan: jedesa: yeah, recursion can come later, and I don't think we have time for classes today
amgigojapan: jedesa: you can take a whole week to do this homework
jedesa: I'll give it a try later
jedesa: okay amigojapan
— jedesa kin kon kan kon
jedesa: yes, thanks for your time today :3
amgigojapan: thanks for your time too!
jedesa's homework print("The Hangman Game: Guess a Distro Edition!") import random, string # pick a random distro def genword(): words = ["CachyOS", "Mint", "MX Linux", "Debian", "EndeavourOS", "Pop!_OS", "Zorin", "Manjaro", "Fedora", "Ubuntu", "AnduinOS", "openSUSE", "Nobara", "elementary", "NixOS", "Bluestar", "KDE neon", "antiX", "BigLinux", "Bazzite", "Arch", "Garuda", "Q4OS", "TUXEDO", "FreeBSD", "PikaOS", "SparkyLinux", "Kali", "AlmaLinux", "Puppy", "Alpine", "MiniOS", "CentOS", "PCLinuxOS", "Tails", "Voyager", "EasyOS", "Linuxfx", "Kubuntu", "Solus", "Lite", "Devuan", "Artix", "Parrot", "AerynOS", "Void", "Exton", "DragonOS", "Omarchy", "ALT", "Rocky", "FunOS", "Lubuntu", "OpenMandriva", "Slackware", "Gentoo", "Commodore", "Peppermint", "deepin", "Ultimate", "Mageia", "PorteuX", "Red Hat", "Xubuntu", "AV Linux", "blendOS", "MODICIA", "Archcraft", "Kodachi", "MocaccinoOS", "ReactOS", "Tiny Core", "ArchBANG", "KaOS", "Bodhi", "GhostBSD", "KDE Linux", "Ultramarine", "Gnoppix", "Vanilla", "ZimaOS", "Calculate", "FydeOS", "Mabox", "Nitrux", "Qubes", "SmartOS", "AxOS", "MagOS", "Feren", "4MLinux", "OpenBSD", "GNOME OS", "Ubuntu Studio", "Chimera", "Proxmox", "Besgnulinux", "Regata", "TrueNAS", "HackerOS", "BunsenLabs", "MakuluLinux", "RebornOS", "Oracle", "Emmabuntüs", "SDesk", "Murena", "Expirion", "Rhino", "Aurora", "Haiku", "Porteus", "Wifislax", "GLF", "Ubuntu MATE", "Endless", "Dr.Parted", "TROMjaro", "VailuxOS", "ChromeOS", "iDeal", "Volumio", "Talos", "GXDE", "Br OS", "NebiOS", "Oreon", "SliTaz", "AUSTRUMI", "DragonFly", "openmamba", "RasPiOS", "Kicksecure", "LinuxHub", "openKylin", "DietPi", "Neptune", "postmarketOS", "Security Onion", "Whonix", "Damn Small", "Athena", "MidnightBSD", "Pardus", "extrox", "Ubuntu Cinnamon", "Ufficio Zero", "Liya", "OmegaLinux", "Genuen", "siduction", "Shanios", "Synex", "Kiro", "ROSA", "GParted", "Lingmo", "pearOS", "Clonezilla", "Mauna", "Nyarch", "Redox", "StormOS", "XIVA Studio", "SystemRescue", "Archman", "Guix System", "Ubuntu Budgie", "LFS", "HeliumOS", "Obarun", "SUSE", "ExTiX", "iodéOS", "Loc-OS", "RefreshOS", "Vendefoul", "Asmi", "Pearl", "CRUX", "T2 Linux", "Debian Edu", "OpenMediaVault", "LainOS", "RELIANOID", "Rescuezilla", "BlueOnyx", "GrapheneOS", "NetHydra", "NuTyX", "AgarimOS", "CuerdOS", "OpenIndiana", "Ubuntu Unity", "IPFire", "Soplos", "SysLinuxOS", "Armbian", "Batocera", "Bluefin", "Exe", "Finnix", "SteamOS", "FreedomBox", "Grml", "Trisquel", "ELEGANCE", "NetBSD", "Univention", "GoboLinux", "Lakka", "Slimbook OS", "Alien-OS", "OPNsense", "Slackel", "Tribblix", "Ubuntu Kylin", "Xray_OS", "BackBox", "HardenedBSD", "NomadBSD", "d77void", "DESERT", "Edubuntu", "KolibriOS", "LibreELEC", "Plop", "UBports", "umbrelOS", "Zephix", "Canaima", "Elive", "ObsidianOS", "openEuler", "Drauger", "Melawy", "MIRACLE", "PakOS", "Pisi", "VyOS", "WM Live", "Arkane", "Sculpt", "Berry", "Daphile", "Mobian", "NethServer", "spirit OS", "Calam", "Plamo", "Redcore", "Refracta", "Vinari", "arcOS", "Luberri", "Venom", "Vipnix", "Aeon", "DynFi", "GuideOS", "Unraid", "Zenwalk", "Adélie", "BSDRP", "FuguIta", "Kamarada", "RED OS", "Tsurugi", "ElysiaOS", "Peropesis", "Slint", "Bedrock", "Crunchbangplusplus", "MAX", "AOSC", "CAINE", "Netrunner", "Shebang", "SolydXK", "XigmaNAS", "46=", "Parch", "RebeccaBlackOS", "Recalbox", "Flatcar", "Kumander", "Lilidog", "PrismLinux", "Solaris", "StartOS", "Accessible-Coconut", "Live Raizo", "Parted Magic", "Pentoo", "Snal", "ATZ Linux", "Clear NDR", "NST", "Ubuntu Pack", "DebLight", "Kamuriki", "LinuxConsole", "TeaLinux", "Zentyal", "DEKUVE", "LliureX", "Predator-OS", "Skywave", "Vine", "XeroLinux", "KANOTIX", "LinuxCNC", "Macaroni", "Runtu", "NethSecurity", "pfSense", "AcreetionOS", "Rockstor", "Fatdog64", "PelicanHPC", "Porteus Kiosk", "UOS", "Zenned", "Exherbo", "gabeeOSLinux", "OsoLinux", "Planeta Tecno", "PLD", "Quarkos", "secureblue", "TileOS", "Ventoy", "AlterOS", "LazyLinux", "Secure-K", "StratOS", "Archriot", "Berserk Arch", "Ditana", "HamoniKR", "Noid", "Origami", "OSMC", "RISC", "Zenclora", "Astra", "Blade", "Flora", "Koozali", "paldo", "Super Grub2", "OmniOS", "Escuelas", "Helwan", "mAid", "rlxos", "AnuBitux", "Catbird", "Essora", "Salix", "TTOS", "Uncom", "Thinstation", "YunoHost", "AçorOS", "AfagOS", "DAT", "Lernstick", "Linux Schools", "Milis", "PelandukOS", "Vincent", "Ximper", "OSGeoLive", "PrimTux", "Smoothwall", "TurnKey", "UBOS", "Asahi", "BRGV-OS", "Green", "nakeDeb", "Xebian", "Bicom", "LangitKetujuh", "NexentaStor", "TobbeOS", "Vitalinux", "BOSS", "LxPup", "OviOS", "Quirinux", "UBLinux", "Ubuntu Sway", "Fluxuan", "FUSS", "Maple", "REMnux", "Skudonet", "AiO-SRT", "CloudLinux", "Nemesis", "RDS", "RSS", "Senpai", "Side", "XCP-ng", "< 1 or not g.isalpha(): print("Guess with case-sensitive alphabet:") g = str(input()) return g # run until quit or game over retry = True score = 0 while retry: # generate word word = genword() print("Hint:", len(word), "characters long") # print("ANSWER:", word) # how hangman works # the word list should have its copy value hidden # player make a guess # if it's wrong, add to wrong guess, advance to gallows # if it's correct, update character display, halt gallows # if health ran out, game is over # if guessed all characters correctly, continue game # hangman start # 10 health points # 20 if long word health = 20 if len(word) > 12 else 10 if health > 10: print("Good News! HP x20") progress = [ "_" for i in range(0, len(word)) ] wrong = [] while health > 0 and "_" in progress : iscorrect = False pguess = guess() # player guess iscorrect = pguess in word # check guess if pguess in wrong or pguess in progress: print("Already Guessed!") elif iscorrect: print("Correct!") progress = gallows(word, progress, pguess) else: print("Wrong!") wrong.append(pguess) health = health - 1 print("Health :", health) print("Progress:", progress) print("Miss :", wrong) # check win if "_" in progress: print("Hanged!") retry = False else: print("Good Work") score = score + 1 # retry game if retry: print("Enter '0' to exit or any key to continue") if str(input()) == "0": retry = False print("Game Over. Correct guesses:", str(score) + " word:" + word)