Question

in the scheme programming language implement a game of rock paper scissors between a user and...

in the scheme programming language implement a game of rock paper scissors between a user and the computer.

Only the following scheme subsets should be used:

Special symbols (not case sensitive in our version (R5RS), but is in R6RS):
a. Boolean: #t (else) and #f
b. Characters: #\a, #\b ... #\Z
c. Strings: in double quotes


3. Basic functions:
a. quote
b. car
c. cdr
d. c _ _ _ _ r, where each _ is either “a” or “d”
e. cons
f. cond
g. list
h. append
i. length
j. reverse
k. member
l. map


4. Boolean functions:
a. boolean? — #t or #f
b. pair? — '(a b c) and '(a.b), but not '()
c. list? — '(a b c) and '(), but not '(a.b)
d. atom?
e. symbol?
f. number?
g. char? — literals written with #\ prefix, followed by the character, Unicode
code, or special character descriptor (#\tab, #\linefeed, #\newline, #\space,
etc.)
h. string? — sequence of characters enclosed in double quotes (e.g., "Hello\n")
i. null?
j. eq?
k. equal?
l. and, or, not
m. char=?
n. string=?
o. negative?

5. Arithmetic functions
a. +, -
b. *, /, mod
c. =, <, >, <=, >=
d. random
e. min, max
f. sqrt, exp, log, abs
6. Definitions — for data and functions, to associate a name with a value. You may only
use them for functions in your assignment; you may use them on data for testing
purposes.
a. E.g. (define (functionName formalParams) body)
b. E.g. (define functionName (lambda (formalParams) body))
c. E.g. (define dataName 2) ;can’t use this in your code, just for testing
Note that assignments, such as (set! variable expression ), should not be used in your
formal program, but prove invaluable in testing. Assignments break the functional
style.


7. I/O stuff:
a. symbol->string
b. string->symbol
c. string->list
d. list->string
e. char->integer
f. integer->char
g. read – returns an atom
h. read-char
i. peek-char
j. display
k. newline


8. Special functions:
a. apply
b. eval

Homework Answers

Answer #1

# import random module
import random

# Print multiline instruction
# performstring concatenation of string
print("Winning Rules of the Rock paper scissor game as follows: \n"
                               +"Rock vs paper->paper wins \n"
                               + "Rock vs scissor->Rock wins \n"
                               +"paper vs scissor->scissor wins \n")

while True:
   print("Enter choice \n 1. Rock \n 2. paper \n 3. scissor \n")
  
   # take the input from user
   choice = int(input("User turn: "))

   # OR is the short-circuit operator
   # if any one of the condition is true
   # then it return True value
  
   # looping until user enter invalid input
   while choice > 3 or choice < 1:
       choice = int(input("enter valid input: "))
      

   # initialize value of choice_name variable
   # corresponding to the choice value
   if choice == 1:
       choice_name = 'Rock'
   elif choice == 2:
       choice_name = 'paper'
   else:
       choice_name = 'scissor'
      
   # print user choice
   print("user choice is: " + choice_name)
   print("\nNow its computer turn.......")

   # Computer chooses randomly any number
   # among 1 , 2 and 3. Using randint method
   # of random module
   comp_choice = random.randint(1, 3)
  
   # looping until comp_choice value
   # is equal to the choice value
   while comp_choice == choice:
       comp_choice = random.randint(1, 3)

   # initialize value of comp_choice_name
   # variable corresponding to the choice value
   if comp_choice == 1:
       comp_choice_name = 'Rock'
   elif comp_choice == 2:
       comp_choice_name = 'paper'
   else:
       comp_choice_name = 'scissor'
      
   print("Computer choice is: " + comp_choice_name)

   print(choice_name + " V/s " + comp_choice_name)

   # condition for winning
   if((choice == 1 and comp_choice == 2) or
   (choice == 2 and comp_choice ==1 )):
       print("paper wins => ", end = "")
       result = "paper"
      
   elif((choice == 1 and comp_choice == 3) or
       (choice == 3 and comp_choice == 1)):
       print("Rock wins =>", end = "")
       result = "Rock"
   else:
       print("scissor wins =>", end = "")
       result = "scissor"

   # Printing either user or computer wins
   if result == choice_name:
       print("<== User wins ==>")
   else:
       print("<== Computer wins ==>")
      
   print("Do you want to play again? (Y/N)")
   ans = input()


   # if user input n or N then condition is True
   if ans == 'n' or ans == 'N':
       break
  
# after coming out of the while loop
# we print thanks for playing
print("\nThanks for playing")

The screenshot of code:

Output:

Note: Plzzz don' t give dislike.....Plzzz comment if u have any problem i will try to resolve it.......

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
There is a simple encryption scheme that is called “Caesar Cipher”. In a “Caesar Cipher”, the...
There is a simple encryption scheme that is called “Caesar Cipher”. In a “Caesar Cipher”, the letters in a message are replaced by the letters of a “shifted” alphabet. A “Caesar Cipher” encodes a message by shifting each letter in a message by a constant amount of k. If k is 5, A becomes F, B becomes G, C becomes H and so on. Let's use Queue to encode and decode the encrypt message. Set k as -5 and decipher...
Using the C programming language implement Heapsort in the manner described in class. Here is some...
Using the C programming language implement Heapsort in the manner described in class. Here is some example code to use as a guideline. Remember, you need only implement the sort algorithm, both the comparison and main functions have been provided. /* * * after splitting this file into the five source files: * * srt.h, main.c, srtbubb.c, srtinsr.c, srtmerg.c * * compile using the command: * * gcc -std=c99 -DRAND -DPRNT -DTYPE=(float | double) -D(BUBB | HEAP | INSR |...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(),...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(), and isEmpty(). For this assignment, enqueue() will be implemented in an unusual manner. That is, in the version of enqueue() we will use, if the element being processed is already in the queue then the element will not be enqueued and the equivalent element already in the queue will be placed at the end of the queue. Additionally, you must implement a circular queue....
define a function,character, with parameter values and word that takes in a dictionary of letter values...
define a function,character, with parameter values and word that takes in a dictionary of letter values and a string. Based on the values in the dictionary, return the "score" that corresponds with the word parameter. NOTE: Assume all words and letter values will be lowercase. examples: values = {'a': 5, 'b': 5, 'c': 5, 'd': 5, 'e': 5, 'f': 5, 'g': 5, 'h': 5, 'i': 5, 'j': 5, 'k': 5, 'l': 5, 'm': 5, 'n': 5, 'o': 5} character(value,"ade") will...
pseudocode please!! Assignment6C: P0\/\/|\|3D. In the early 80s, hackers used to write in an obfuscated, but...
pseudocode please!! Assignment6C: P0\/\/|\|3D. In the early 80s, hackers used to write in an obfuscated, but mostly readable way called “leet” – short for “elite”. In essence, it was a simple character replacement algorithm, where a single “regular” character was replaced by one or more “leet” characters; numbers remained the same. Here’s one of the most readable versions: a 4 g 9 m /\\/\\ s $ y ‘/ b B h |-| n |\\| t 7 z Z c (...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems that need to be corrected. Your task is to complete it to course style and documentation standards CS 200 Style Guide. This project will be human graded. This class contains a set of methods. The main method contains some examples of using the methods. Figure out what each method does and style and document it appropriately. The display method is done for you and...
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as...
ANSWER IN C++ ONLY A string of characters including only alphabets (lowercase letters) is provided as an input. The first task is to compute the frequency of each character appearing in the string. In the output, the characters have to be arranged in the same order as they appear in the input string. Then characters have to be rearranged, such that all the characters having a specific frequency, say xx, come together. Let the frequency of a character, lying in...
C Programming. Do not use a function in the solution. Assignment 6 This assignment focuses on...
C Programming. Do not use a function in the solution. Assignment 6 This assignment focuses on using arrays. Instructions Create a program called arrays.c that does the following: 1. Prompt the user for a string (<= 100 characters). (using the attached file: AS06Data.txt) AS06Data.txt file contains the text " Instructions: When your executing program displays "Enter string 1:" starting with T, select the line of text below, copy with ctrl-c, then type ctrl-v THIS IS a test of string 0123456789...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT