1

I am trying to graph as a function of r the probability for finding the electron in the ground state of the two dimensional and three-dimensional hydrogen atom. The code I have right now is:

import math
import matplotlib.pyplot as plt
import numpy as np

def three_dimensional(radius):
    bohr = (5.2917721067)*10**(-11)
    use_radius = []
    for i in radius:
        new_rad = bohr*i
        use_radius.append(new_rad)

    answers = []
    for i in use_radius:
        R_r = (2//(bohr)**(3//2))*math.exp(-i/bohr)
        answers.append(R_r)

    probability = []
    for i in answers:
        probs = i^2
        probability.append(probs)

    print(answers)

    return plt.contour(answers, probability)

I am getting the error:

TypeError: unsupported operand type(s) for ^: 'float' and 'int'

What is the best way to fix this?

David Z
  • 128,184
  • 27
  • 255
  • 279

1 Answers1

2

You want the ** operator, which is the exponent operator in Python, instead of ^. So this line should be:

for i in answers:
    probs = i**2
    probability.append(probs)
DavidG
  • 24,279
  • 14
  • 89
  • 82
Todd Price
  • 2,650
  • 1
  • 18
  • 26