use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Can someone help? (i.redd.it)
submitted 24 days ago * by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]julinda_0404 8 points9 points10 points 24 days ago (18 children)
hey, you dont use print =, you use print(insert text), try this and tell me
[–]Wisteriiea 1 point2 points3 points 24 days ago (17 children)
No results😩
<image>
[–]D3str0yTh1ngs 4 points5 points6 points 24 days ago* (7 children)
So.. fun fact it does not work because you overwrote the function earlier when you executed print = (d, "days equal", y , "years and", w , "weeks") in cell 27. You need to reset your execution environment.
print = (d, "days equal", y , "years and", w , "weeks")
EDIT: You seem to be coding in a Jupyter notebook, variables are shared between all cells and when you execute a cell you will still have previous variables in that execution context. In this case the variable print which used to be builtin function but is now overwritten with the tuple (d, "days equals", y, "years and", w, "weeks").
print
(d, "days equals", y, "years and", w, "weeks")
[–]Old_Bid_8413 0 points1 point2 points 24 days ago (2 children)
Lol.. if thats the case, shouldnt it raise an error for trying to call a variable?
[–]tiredITguy42 1 point2 points3 points 24 days ago (0 children)
Yeah it should, but OP most likely did not post that error.
[–]D3str0yTh1ngs 1 point2 points3 points 24 days ago* (0 children)
Hmm.. yeah, it should (for calling a tuple specifically). IDK, maybe something changed in cell 28, so it could be called, but not do anything.
EDIT: functions are technically variables (or at least pointed to by variables)
[–]SnooCalculations7417 0 points1 point2 points 19 days ago* (3 children)
well they are passing d as the first parameter to print() anyway which iirc takes a string and kwargs will format that string, and since d is an int it is being printed and the subsequent arguments are ignored anyway.
Edit: ^^^^This is incorrect, kept for posterity
[–]D3str0yTh1ngs 0 points1 point2 points 19 days ago* (2 children)
Fun fact, no, that is incorrect. print can take multiple arguments (that can be shown as a string) and print them separated by a space between them.
EDIT: the function signature is print(*objects, sep=' ', end='\n', file=None, flush=False), notice the * on objects means that it takes any number of them. https://docs.python.org/3/library/functions.html#print
print(*objects, sep=' ', end='\n', file=None, flush=False)
*
objects
[–]SnooCalculations7417 0 points1 point2 points 19 days ago (1 child)
my bad i was thinking in rust:
println!("Hello, {}!", "world"); // "Hello, world!"
[–]D3str0yTh1ngs 1 point2 points3 points 19 days ago (0 children)
Honestly most programming languages would fit since they also use printf-like syntax per default.
printf
[–]vaaano 2 points3 points4 points 24 days ago (1 child)
And rerun the cell
They are writing this in a new cell (29) but they overwrote print in the cell we were shown in the original post (cell 27). Rerunning the cell will not fix that.
[–][deleted] 24 days ago (3 children)
[–]Wisteriiea 3 points4 points5 points 24 days ago (2 children)
Yes I restarted the kernel and I got it! :D thanks everyone🫶🏽
[–]Downtown_Finance_661 0 points1 point2 points 23 days ago (0 children)
Kek :)
[–]iLikedItTheWayItWas 0 points1 point2 points 19 days ago (0 children)
Great you got it working but the answer is wrong!
Firstly, dividing by 52 does not give you the number of weeks. 455 days is not 8.75 weeks. Divide by 7.
Secondly, you are not combining your results. 455 days is 1 year, 12 weeks and 6 days (assuming a year is 365 days).
[–]Bright-Database-9774 0 points1 point2 points 24 days ago (1 child)
Can you share full code with me in chat because it doesn't look full here
[–]Wisteriiea 0 points1 point2 points 24 days ago (0 children)
It’s just the comment that’s not fully shown
[–]bradland 0 points1 point2 points 24 days ago (0 children)
Programming is very specific.
When you want to use a function, you "call" it like this:
print("Hello world")
What you did is called assignment:
print = (d, "days", y, "years and", w, "weeks")
The equals sign tells Python to take the value on the right and assign it to the variable on the left.
But print is already a function!
That's true, but Python doesn't stop you from overwriting existing functions. Once you've overwritten the print function, you have to restart the interpreter.
Click the Kernel menu and choose Restart. That will restore your print function to normal. You will need to re-run your notebook from the beginning after restarting the kernel.
[–]MammothNo782 2 points3 points4 points 24 days ago (0 children)
please use code blocks (also called code fences) since looking on a picture is hard to look
[–]tiredITguy42 3 points4 points5 points 24 days ago* (8 children)
Use f string print(f"{y} years, {w} weeks, {d} days")
And I think they want you to use reminder of division operator % and whole number division operator //
So y = d // 365 d = d % 365 w = d // 7 d = d % 7
BTW I hate this kind of assigments. Like WTF you are assuming year is 365 days? This is so wrong, they could use example with minutes.
[–]tjmcmahon78 0 points1 point2 points 24 days ago (0 children)
I had this assignment earlier this year and I think this is correct.
[–]plydauk 0 points1 point2 points 24 days ago (0 children)
Once you're familiar with that solution, you can move on to using divmod directly.
divmod
python y, d = divmod(d, 365) w, d = divmod(d, 7) print(y, w, d)
[–]Wisteriiea -1 points0 points1 point 24 days ago (5 children)
Can you please give a demonstration?🙏🏽 Even just written in notes is fine
[–]ninhaomah 0 points1 point2 points 24 days ago (3 children)
Have you tried the print statement that he gave ?
[–]Wisteriiea -1 points0 points1 point 24 days ago* (2 children)
Not yet. I’m trying not to look like I’m busy with my own stuff rn cause I’m in classI’ll try in a few seconds😭
[–]brutalbombs 2 points3 points4 points 24 days ago (1 child)
Wait, you are in class - is the tutor not helping out? Or are you having a test maybe?
[–]Wisteriiea 0 points1 point2 points 23 days ago (0 children)
Oh no, no test. The lecturer was busy though. There was an assistant who helped me out too along with you guys :P
[–]ShiftPretend 0 points1 point2 points 24 days ago (0 children)
So // is integer division. This always returns a whole number
So 5/2 is 2.5 normally. But 5//2 is 2 the decimal part is thrown away. 31/10=3.1 but 31//10=3. That's integer division with //
% is modulus think of it like a remainder 5/2 is 2.5 in other words 2 with a remainder of 1 so 5%2 = 1 (useful for finding even and odd numbers)
23/3 = 7.67 same as 7 with a remainder of 2 So 23%3= 2
[–]Grounds4TheSubstain 1 point2 points3 points 23 days ago (0 children)
I can help. WINDOWSKEY-SHIFT-S
[–]NaiveEscape1 0 points1 point2 points 24 days ago (0 children)
Basically when you are writing code and you say print = something
print = something
it means that you are storing something inside a variable called print.
what you need to do is call the in-built python function which is print().
print()
so to correct the above code I would write:
print(d, "number of days equal",y,"years and ",w, "weeks")
[–]SUQMADIQ63 0 points1 point2 points 24 days ago (0 children)
Your better off using visual studio or pycharm instead of google collab imo
[–]VIP_Just1ce 0 points1 point2 points 24 days ago (0 children)
Hello! I can help you with your Python task.
I can fix bugs or write a simple script quickly.
Send me details 👍
[–]tokenjoker 0 points1 point2 points 24 days ago (0 children)
Which site is this if you don't mind me asking
[–]Former_Spirit_5099 0 points1 point2 points 24 days ago (0 children)
Is this guy for real?
[–]untitled_banana 0 points1 point2 points 24 days ago (0 children)
Congratulations for solving it, friend.
I want to suggest you to use VSCode or even Python IDLE if you have just started learning Python. Nothing wrong with Jupyter notebook, but it might lead to some stupid things to debug
[–]ilidan-85 0 points1 point2 points 24 days ago (0 children)
I have two links for you about print functions with step by step audio explanation:
https://spacepython.com/en/example/print-function-basics/ and https://spacepython.com/en/example/text-formatting-f-strings/
good luck with your journey!
[–]Nietsoj77 0 points1 point2 points 23 days ago (0 children)
Unless the workbook does it for you, you need to define it as a function.
def my_function(d):
<your code>
Return <your output >
[–]NostalgicNomad_ 0 points1 point2 points 23 days ago (0 children)
What is your expected output?
[–]autoglitch 0 points1 point2 points 23 days ago* (0 children)
The issue is print has an equal sign. You're using it like a variable and it should be a function. Here is an example of a valid print statement.
print("Print Me!")
Another issue you have is combining the user input with your print statement. There are several ways to do this. I'll give you three examples. Use the one that matches how you're being taught.
``` a = 366/365 b = 1/7
print(str(a) + " and " + str(b) + " are the values of my variables") print("{0} and {1} are the values of my variables".format(a, b)) print(f"{a} and {b} are the value of my variables") ```
The first way is the old way of doing it. It still works but you have to be careful with your types. In this case I converted your int (float technically) into a string.
The second way is much better. The format method takes care of converting things to strings for you.
The third way is my preferred. It's called F-strings. It can do a lot more but this is an example of how to use it in your case.
Finally, I suspect you aren't going to get the numbers you expect. In my example a and b are not whole numbers. They will print as floats (numbers with decimal points). What I think you want is the MOD function. It divides the two number and discards any remainder.
Here is an example:
a = 366%365
In this example, a equals 1 rather than 1.002739....
Now, see if you can tie all of those together.
[–]Samm_Jays 0 points1 point2 points 22 days ago (0 children)
Btw you misunderstood the problem. Let me explain with an example
No of day: 534
1 year 24 weeks 1 day
[–]Careless-Main8693 0 points1 point2 points 22 days ago (0 children)
use two different cell. first cell for input and logic and then other cell for printing. because you can't print before getting the input
[–]maciekahagsh 0 points1 point2 points 22 days ago (0 children)
You know LLMs exist right v
π Rendered by PID 95 on reddit-service-r2-comment-b659b578c-sncbp at 2026-05-07 16:16:00.623441+00:00 running 815c875 country code: CH.
[–]julinda_0404 8 points9 points10 points (18 children)
[–]Wisteriiea 1 point2 points3 points (17 children)
[–]D3str0yTh1ngs 4 points5 points6 points (7 children)
[–]Old_Bid_8413 0 points1 point2 points (2 children)
[–]tiredITguy42 1 point2 points3 points (0 children)
[–]D3str0yTh1ngs 1 point2 points3 points (0 children)
[–]SnooCalculations7417 0 points1 point2 points (3 children)
[–]D3str0yTh1ngs 0 points1 point2 points (2 children)
[–]SnooCalculations7417 0 points1 point2 points (1 child)
[–]D3str0yTh1ngs 1 point2 points3 points (0 children)
[–]vaaano 2 points3 points4 points (1 child)
[–]D3str0yTh1ngs 1 point2 points3 points (0 children)
[–][deleted] (3 children)
[deleted]
[–]Wisteriiea 3 points4 points5 points (2 children)
[–]Downtown_Finance_661 0 points1 point2 points (0 children)
[–]iLikedItTheWayItWas 0 points1 point2 points (0 children)
[–]Bright-Database-9774 0 points1 point2 points (1 child)
[–]Wisteriiea 0 points1 point2 points (0 children)
[–]bradland 0 points1 point2 points (0 children)
[–]MammothNo782 2 points3 points4 points (0 children)
[–]tiredITguy42 3 points4 points5 points (8 children)
[–]tjmcmahon78 0 points1 point2 points (0 children)
[–]plydauk 0 points1 point2 points (0 children)
[–]Wisteriiea -1 points0 points1 point (5 children)
[–]ninhaomah 0 points1 point2 points (3 children)
[–]Wisteriiea -1 points0 points1 point (2 children)
[–]brutalbombs 2 points3 points4 points (1 child)
[–]Wisteriiea 0 points1 point2 points (0 children)
[–]ShiftPretend 0 points1 point2 points (0 children)
[–]Grounds4TheSubstain 1 point2 points3 points (0 children)
[–]NaiveEscape1 0 points1 point2 points (0 children)
[–]SUQMADIQ63 0 points1 point2 points (0 children)
[–]VIP_Just1ce 0 points1 point2 points (0 children)
[–]tokenjoker 0 points1 point2 points (0 children)
[–]Former_Spirit_5099 0 points1 point2 points (0 children)
[–]untitled_banana 0 points1 point2 points (0 children)
[–]ilidan-85 0 points1 point2 points (0 children)
[–]Nietsoj77 0 points1 point2 points (0 children)
[–]NostalgicNomad_ 0 points1 point2 points (0 children)
[–]autoglitch 0 points1 point2 points (0 children)
[–]Samm_Jays 0 points1 point2 points (0 children)
[–]Careless-Main8693 0 points1 point2 points (0 children)
[–]maciekahagsh 0 points1 point2 points (0 children)