r/PythonLearning • • May 23 '26

Discussion Do you think it is dangerous?

Post image

This code can be dangerous if values are high.

It should have a limit function. I tested Hello at 200 times but in the app there is no limit. It can damage RAM.

0 Upvotes

23 comments sorted by

12

u/Special-Arrival6717 May 23 '26

OS will kill the process if it runs out of RAM, your RAM will be safe

12

u/Don_Ozwald May 23 '26

Damage the RAM? Could you elaborate on that?

2

u/CptMisterNibbles May 24 '26

They cannot, because it’s not true. They think computers have no means of detecting issues like a thread rapidly consuming ram with no bound and terminating the process

4

u/ianrob1201 May 23 '26

One of the good things about python as a first programming language is that you can't mess it up too badly. Absolute worst case is that the app hangs and crashes. Do your best, go for 100,000 and see what happens. I don't think it'll even crash, but it might take a very long time to run!

3

u/nicodeemus7 May 23 '26

Help I did something wrong, it printed "100,000" hello world times

1

u/Sether_00 May 24 '26

Just download more RAM.

3

u/pstanton310 May 23 '26

No, the code isn’t slightly dangerous.

3

u/CIS_Professor May 23 '26
  1. No, it isn't dangerous.

  2. Next time, maybe try it:

2

u/AngriestCrusader May 23 '26

There's no universe where executing this code would be dangerous.

2

u/QuestNetworkFish May 23 '26

Your ram is designed to be written to and entirely filled up the majority of the time. It is not possible to damage ram through software. The worst case scenario is that it crashes the OS and you have to restart the computer, but most OSes, particularly mobile OSes like Android are designed to terminate apps if they misbehave and try to consume too much memory 

2

u/SCD_minecraft May 23 '26

Let's say you have 8GB of RAM

Each ASCII characters is one byte

So you would need to input 8,000,000,000

However, before that you are gonna get MemoryOverflow error and crash the program (freeing up all the space taken)

2

u/Same_Physics_6496 May 23 '26

too many high values, you will become a dangerous python

2

u/[deleted] May 25 '26

yes! this is super advanced hacker virus 10000, you should be very cautious with this stuff

1

u/DisasterHarmony May 23 '26

You should add conditional instruction for safety:

if b >= 2:
print("The code is too dangerous if values are high. Choose lower number like 1 or 2.")
else:
print(a*b)

1

u/ConfidentCollege5653 May 23 '26

Is 2 valid or not?

1

u/ImMrAndersen May 23 '26

Yesn't, for safety

1

u/BuddyLlght May 23 '26

You can always download more ram 🤷‍♂️

1

u/WorkAroundG60 May 23 '26

Many years ago, it would be similar to memory overflow style attacks. Smash the system with replicated things, memory fills, crashes and potentially corrupts data.

Isn't really an issue any more

1

u/SnooCalculations7417 May 23 '26

It won't be larger than the max integer size, x the word. Relatively fine memory rise

1

u/Unequivalent_Balance May 23 '26

8192 petabytes on a 64-bit system… I think that’s going to run out of RAM.

1

u/SCD_minecraft May 23 '26

Python does not have (effective) int limit

All ints are by deafult (and only) BigInts aka they can and will take megabytes of space if they need to

Only floats are capped to f64