A Noob's Adventures in Coding: Chat Bot

in #hive-1635212 years ago

I'm new to Python, so this took over an hour of trial and error to get right, and since my knowledge of technical Russian is extremely lacking, I'm not going to write in my usual bilingual format. Anyway, I thought I might share this little adventure. The first step was to program a computer to process inputs. This is a simple function:

image.png

Note that these are lines 4 and 5. That's because this simple operation is part of a larger program that I wrote around the input exercise. This is the beginnings of a chat bot:

image.png

This is a very simple Python program, I think we can all agree. However, when I decided to write a Russian version (I am making literal Russian bots!), the program more than doubled in size from 19 lines to 55 and contains not one, but two nested while loops! The reason has to do with a quirk of Russian grammar. If you can't figure it out from looking at the code, let me know, and I'll happily explain.

image.png
image.png

Actually, I need to explain anyway, because in order to write a while loop that did what I wanted (reporting the value of the ones place in any given integer), I experimented with a separate program to see if I could get the computer to do what I want, and then copy and paste the relevant code blocks into the chat program. This is what I came up with:

image.png

The extra "print" commands are in there to show me that the program is performing the correct calculations. This is the output, from an input of 59:

image.png

Once I have that value, I can assign a grammar variable to it, which will alter the chat bot's output accordingly. I'm sure there's a more efficient way to do this, but I haven't gotten to that point yet. As of this post, I have been playing around with Python for exactly one week, so I don't really know what I'm doing. Granted, this isn't my first programming language (that would be industrial g-code), so I'm not completely new to coding.

Oh, I guess I should show you Kaja-bot's output!

image.png

Anyway, I had fun. What do you think? Am I right to find this mildly humourous, or am I just needlessly giddy from staring at a screen for too long?

Sort:  

He came online a year ago, so he is one year old and probably has access to more knowledge than me and you have combined 😂😂😂🦅

Well friends, I've already figured out a way to shorten the program from 55 lines down to 46, and that was to define the ones place not by means of a while loop, but by slicing an array. Here is the result (lines 1 and 2 are unchanged), hopefully you can read it:

image.png

If not, here is the relevant code:

image.png

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

Congratulations @steampunkkaja! You received a personal badge!

You powered-up at least 10 HIVE on Hive Power Up Day! This entitles you to a level 1 badge.
Participate in the next Power Up Day and try to power-up more HIVE to get a bigger Power-Bee.
May the Hive Power be with you!

You can view your badges on your board and compare yourself to others in the Ranking

Check out our last posts:

Hive Power Up Month Challenge - January 2023 Winners List
Be ready for the February edition of the Hive Power Up Month!
Hive Power Up Day - February 1st 2023
The Hive Gamification Proposal
Support the HiveBuzz project. Vote for our proposal!

Congratulations @steampunkkaja! You received a personal badge!

You powered-up at least 10 HIVE on Hive Power Up Day!
Wait until the end of Power Up Day to find out the size of your Power-Bee.
May the Hive Power be with you!

You can view your badges on your board and compare yourself to others in the Ranking

Check out our last posts:

Hive Power Up Month Challenge - January 2023 Winners List
Be ready for the February edition of the Hive Power Up Month!
Hive Power Up Day - February 1st 2023
The Hive Gamification Proposal
Support the HiveBuzz project. Vote for our proposal!