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

DR - Racket Tutorial 2

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)
11 views3 pages

DR - Racket Tutorial 2

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
You are on page 1/ 3

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]”.

Dr.Racket
(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.

Dr.Racket
(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.

Dr.Racket
(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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy