Study drill 3 ex19 , i want to know if this right and if it is , how i can make it better

from sys import argv 

from os.path import exists

# My function 

def coffee_and_cigarettes(coffe_per_day , cigarettes_per_day):

    print(f"I'm drinking {coffe_per_day} {arg1} and, \nI'm smoking {cigarettes_per_day} {arg2}\n")

    print(" 'IT WILL KILL YOU ONE DAY'")

    print("\t'STOP SMOKING!'\n")


# First way ARGV
script, arg1, arg2 = argv

K = "Senseo"

C = "L&M"

KN = 3

CN = 10

# Second way variables 

print("To go through my day : ")

coffee_and_cigarettes(K, C)

# Third way string

print("But If I can't find it in store :")

coffee_and_cigarettes("Perla", "PALL MALL")

# Fourth way doing the math

print("On a normal day :")

coffee_and_cigarettes(KN + 2, CN)

#Fifth way combining string with math 

print("On a busy day :")

coffee_and_cigarettes("4 cups of Senseo", CN + 3 )

# Sixth way combining variables with math 

print("on a stressful day :")

K1 = "6 cups of Senseo "

K2 = "or 7 cups of senseo"

CN1 = 7

coffee_and_cigarettes(K1 + K2, CN + CN1)


# Seventh way Input

print("On free day :")

CN2 = input(">")

KN2 = input(">")

coffee_and_cigarettes(KN2, CN2)

# Eighth way Exists 

print("But I like Senseo and L&M more , beacuse If I'm using other brands feels like :")

txt = "X"

txt1 = "Y"

coffee_and_cigarettes(exists(txt), exists(txt1))

# Ninth way Len 

I1 = input("file1\t")

I2 = input("file2\t")

W1 = open(I1, 'w').write("Tasty")

W2 = open(I2, 'w').write("HARMFUL SHIT")

L1 = open(I1).read()

L2 = open(I2).read()

coffee_and_cigarettes(len(L1), len(L2))

# Tenth way INT

INT1 = int(input(">"))

INT2 = int(input(">"))

coffee_and_cigarettes(INT1, INT2) 

Welcome @khalil! :slight_smile:
Would you do me a favor and add code tags around your code?

# your code


#your code

Then your code will look so beautiful that it will entice us all to read it. You’ll get tons of constructive feedback. :wink:

@zedshaw Could you make a sticky post telling people how to do this? It seems to be totally not obvious.

I wonder if it’s just people used to using the </> markdown attribute as that’s particularly familiar these days.

ohh yes , I did change it , much better now , thanks.

Alright thanks for moving your question here, but can you please add what it is you want people to do with the code you posted? Do you want a review? What do you have questions about?

yes I want a review , i want to know if I’m understanding something at this point of the book. thanks

Looks fine for that point in the book. My only criticism is you use variable names that aren’t good style.


What do those mean anyway? Use full words to describe what they’re used for instead of single letters and numbers. Also, later on CAPITALIZED variables will mean something different so start using lowercase for your variables.

1 Like

I think that’s what I’ve done. Sadly I kinda struggled and hope it works when I use ``` or [code]. Makes me doubt myself.

Can you elaborate more? Are you saying trying to wrap your code with ``` or [code][/code] makes you doubt yourself? Why is that?

When posting code, I’ve learn to use one or the other. However I’ve seem to struggled in the past to get it to format properly. Re-writing or deleting post to correct it. Even when it works I seem to expect it to not then see that it does. Also that I have been studying for well over a year, have repeated chapters and even restarted the book, I would think posting code would not make me take pause but be more ‘natural’. Which in turn raises self doubt about my programming skills/ability.

Interesting. I wonder if you have your screen so small you can’t see the preview output on the right. Like I’m typing this right now and if I do this:

# code goes here

I see it actually format the code correctly on the right hand side of the screen in an example output. If I’m doing a large post I grab the === grippy on the blue bar at the top of the entry and move it up to take up most of the screen. Then I can see it all working just fine.

Down in the bottom right, also look for “show preview >>” 'cause if you see that then you’re hiding the preview that’ll show you if you’re doing it right.

Then, if you have anxiety about this, just start a thread, expand the editor up, turn on the preview, and write up a bunch of fake posts with code until you’re comfortable with it. Probably wouldn’t take too long.

Thank you sir. I’ll look into those when I am back on my PC.
I appreciate all you are doing.

I thought I had [code] posting down. Then I was getting no 'preview". After several attempts, redo’s and looking up on forum for posting code, I made a realization.
If you are posting something that looks similar to another post, a notice covers the preview. It shows what you typed but not anything in the [code].

Aha! I knew it! So I’m guessing your screen is pretty small and that covers it, or you shrink it or something? If you get a chance, try using the forum on a different computer or a bigger monitor, or shrink the font on your browser down.

Its a decent size monitor, smaller one on the left. Here is a shot of what it does to cover the preview.
And before, part was that I had not expanded it up the way it is here.

Well you can close that message in the top right corner, right?

Yes. but I didn’t realize it was even there. I added code, glanced over, didn’t see the preview, adjusted, deleted, looked up how to use [code] , recopied, readjusted. Then saw the close X . Then I felt like an enlightened dumbass lol

1 Like

Aha! The plot thickens. So it’s not monitor size it’s just the UI for this stupid forum is trying to help you but it covers the most useful thing with a stupid message about how you shouldn’t repeat yourself (because programmers hate that).

Well, now you know. Hit ESC to get rid of that or click on the top right X.

A free service run by Zed A. Shaw for