#๐Ÿ”’ Help with Next assignment!

34 messages ยท Page 1 of 1 (latest)

rich scaffoldBOT
#

@naive mulch

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

naive mulch
#

import numpy as np
import numpy.random as rd
import matplotlib.pyplot as plt

def make_random_array(scale, size):
result = np.zeros(size)
for i in range(0,size):
result[i] = rd.exponential(scale=scale)
return result

def scale_from_halflife(halflife):
return halflife/np.log(2)

def part_c():
return make_random_array(scale_from_halflife(10), 10)

def part_d(random_array):
sorted_array = np.sort(random_array)
index_of_first_greater_than_5 = 0
for i in range(0, sorted_array.size):
if sorted_array[i] > 5:
index_of_first_greater_than_5 = i
break
return index_of_first_greater_than_5

def part_e():
result = np.zeros(10000)
for i in range(10000):
rand_array = part_c()
result[i] = part_d(rand_array)
return result

def part_f():
result = part_e()
plt.hist(result)
plt.xlabel('Number of decays in 5 days')
plt.ylabel('Count')
plt.title('Histogram of number of decayed atoms at 5 days')
plt.savefig("Histogram_Decays_Count.png")

def part_g():
result = part_e()
plt.hist(result, density=True)
plt.xlabel('Density of decays in 5 days')
plt.ylabel('Density')
plt.title('Density Histogram of number of decayed atoms at 5 days')
plt.savefig("Density_Histogram_Decays_Count.png")

def part_h():
result_part_e = part_e()
histogram, _ = np.histogram(result_part_e, density=True)
result = 0
for i in range(len(histogram)):
result = result + i*histogram[i]
return result

rich scaffoldBOT
#

Hey @naive mulch!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
naive mulch
#

def backup_main():
sizes_to_test = [100,1000,10000,1000000]
for size in sizes_to_test:
scale = scale_from_halflife(10)
randarray = make_random_array(scale, size)
plt.hist(randarray,bins=100)
plt.savefig("Histogram_"+str(size)+".png")
print("Done! \n")

if name == "main":
result_part_c = part_c()
f = open("result_part_c.txt","w")
f.write(str(result_part_c))
f.close()

result_part_d = part_d(result_part_c)
f = open("result_part_d.txt","w")
f.write(str(result_part_d))
f.close()

result_part_e = part_e()
f = open("result_part_e.txt", "w")
f.write("")
f.close()
f = open("result_part_e.txt", "a")
for i in range(0,result_part_e.size):
f.write(str(result_part_e[i]) + ", ")
f.close()

result_part_h = part_h()
f = open("result_part_h.txt","w")
f.write(str(result_part_h))
f.close()

The likelihood to decay in 5 days is the cumilative distribution at 5.

We can calculate f(5). Hence f(5)=1-e^(-lamda*5)

Lamda = ln(2)/half-life

Since we have 10 atoms, we can multiply f(5)=1-e^(-lamda*5) by 10.

The value received is approximately three, which alligns with part h.

part_f()
part_g()

#

prior code ^^

toxic scroll
#

could you please use syntax highlighting in your pastes

naive mulch
#

wait that might be a tad bit small

#

im having trouble with it as my code is way too long

#

``import numpy as np
import numpy.random as rd
import matplotlib.pyplot as plt

def make_random_array(scale, size):
result = np.zeros(size)
for i in range(0,size):
result[i] = rd.exponential(scale=scale)
return result

def scale_from_halflife(halflife):
return halflife/np.log(2)

def part_c():
return make_random_array(scale_from_halflife(10), 10)

def part_d(random_array):
sorted_array = np.sort(random_array)
index_of_first_greater_than_5 = 0
for i in range(0, sorted_array.size):
if sorted_array[i] > 5:
index_of_first_greater_than_5 = i
break
return index_of_first_greater_than_5

def part_e():
result = np.zeros(10000)
for i in range(10000):
rand_array = part_c()
result[i] = part_d(rand_array)
return result

def part_f():
result = part_e()
plt.hist(result)
plt.xlabel('Number of decays in 5 days')
plt.ylabel('Count')
plt.title('Histogram of number of decayed atoms at 5 days')
plt.savefig("Histogram_Decays_Count.png")

def part_g():
result = part_e()
plt.hist(result, density=True)
plt.xlabel('Density of decays in 5 days')
plt.ylabel('Density')
plt.title('Density Histogram of number of decayed atoms at 5 days')
plt.savefig("Density_Histogram_Decays_Count.png")

def part_h():
result_part_e = part_e()
histogram, _ = np.histogram(result_part_e, density=True)
result = 0
for i in range(len(histogram)):
result = result + i*histogram[i]
return result``

#

``def backup_main():
sizes_to_test = [100,1000,10000,1000000]
for size in sizes_to_test:
scale = scale_from_halflife(10)
randarray = make_random_array(scale, size)
plt.hist(randarray,bins=100)
plt.savefig("Histogram_"+str(size)+".png")
print("Done! \n")

if name == "main":
result_part_c = part_c()
f = open("result_part_c.txt","w")
f.write(str(result_part_c))
f.close()

result_part_d = part_d(result_part_c)
f = open("result_part_d.txt","w")
f.write(str(result_part_d))
f.close()

result_part_e = part_e()
f = open("result_part_e.txt", "w")
f.write("")
f.close()
f = open("result_part_e.txt", "a")
for i in range(0,result_part_e.size):
f.write(str(result_part_e[i]) + ", ")
f.close()

result_part_h = part_h()
f = open("result_part_h.txt","w")
f.write(str(result_part_h))
f.close()

The likelihood to decay in 5 days is the cumilative distribution at 5.

We can calculate f(5). Hence f(5)=1-e^(-lamda*5)

Lamda = ln(2)/half-life

Since we have 10 atoms, we can multiply f(5)=1-e^(-lamda*5) by 10.

The value received is approximately three, which alligns with part h.

part_f()
part_g()

``

true stag
#
def backupmain():
  sizes_to_test = [100,1000,10000,1000000]
  for size in sizes_to_test:
    scale = scale_from_halflife(10) 
    randarray = make_random_array(scale, size)
    plt.hist(randarray,bins=100) 
    plt.savefig("Histogram"+str(size)+".png") 
  print("Done! \n")

if name == "main":
   result_part_c = part_c() 
   f = open("result_part_c.txt","w")
   f.write(str(result_part_c))
   f.close()

   result_part_d = part_d(result_part_c)
   f = open("result_part_d.txt","w")
   f.write(str(result_part_d))
   f.close()

   result_part_e = part_e()
   f = open("result_part_e.txt", "w") 
   f.write("") 
   f.close()
   f = open("result_part_e.txt", "a") 
   for i in range(0,result_part_e.size):
     f.write(str(result_part_e[i]) + ", ")
   f.close()

   result_part_h = part_h() 
   f = open("result_part_h.txt","w")
   f.write(str(result_part_h))
   f.close()```
naive mulch
#

wait lol how did you do that

true stag
#

!code

rich scaffoldBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

naive mulch
#

it doesnt let me submit files on here

true stag
#

if its too long then use !paste

naive mulch
#

!paste

rich scaffoldBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

true stag
#

ohh files, yeah u cant do that

naive mulch
#

lol can i send a screenshot

true stag
#

if its readable

naive mulch
#

Okay, so i have an assignment - this was my last assingment but i need to continue it. Let me send my last assignment

#

this is my new assignment

#

wait i think its supposed to be hw1, i sent the wrong code. mb. give me second

#

what should i do first?

naive mulch
#

Hi, let me know if im confusing you guys

rich scaffoldBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.