0% found this document useful (0 votes)
4 views3 pages

Python and DrRacket String Length & Area Calculations

The document provides tutorials for implementing solutions in DrRacket and Python for three programming scenarios. The first scenario involves calculating the length of a string, the second calculates the surface area of a ring, and the third computes the value of b²-4ac for a quadratic equation. Each scenario includes code examples in both programming languages.

Uploaded by

Randy Bale
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Python and DrRacket String Length & Area Calculations

The document provides tutorials for implementing solutions in DrRacket and Python for three programming scenarios. The first scenario involves calculating the length of a string, the second calculates the surface area of a ring, and the third computes the value of b²-4ac for a quadratic equation. Each scenario includes code examples in both programming languages.

Uploaded by

Randy Bale
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Tutorial 2

Implement solutions for the following scenarios using DrRacket and Python.

1) Design a program to calculate the length of a given string and return the phrase “The
total number of characters in the string is..[answer]”.

[Link]
(define (calculate-length string)

(define length (string-length string))

(string-append "The total number of characters in the string is "


(number->string length))

Python
def calculate_length (string):

return (len(string))

print("The total number of characters in the string is " +


str(calculate_length("Hello World")))
2) Design a program to calculate the surface area of the following disk/ring with the outer
radius and the inner radius given in parameters.

[Link]
(define (area-of-ring outer inner)

(- (area-of-disk outer)

(area-of-disk inner)))

(define (area-of-disk r)

(* pi r r))

Python
def circle_area (radius):

pi = 22/7

return pi*radius*radius

def ring_area (outer,inner):

return circle_area(outer) - circle_area(inner)

print(ring_area(5,3))
3) Calculate the value of b2-4ac for the quadratic formula ax2+bx+c=0, when provided a, b,
c variable values as parameters.
Design the program to give command line inputs as well.

[Link]
(define (roots a b c)

(- (* b b) (* 4 a c))

;;;;;;;; using user input ;;;;;;;;;;;;;;

"Please enter a" (define a (read))

"Please enter b"(define b (read))

"Please enter c"(define c (read))

(- (* b b) (* 4 a c))

Python
def roots(a,b,c):

return b**2 - 4*a*c

print(roots(3,2,1))

You might also like