Question

Part 1: Python code; rewrite this code in C#, run the program and submit - include...

Part 1: Python code; rewrite this code in C#, run the program and submit - include comments

number= 4

guesscount=0

guess=int(input("Guess a number between 1 and 10: "))

while guess!=number:

guesscount=guesscount+1

if guess<number:

print("Your guess is too low")

elif guess>number:

print("Your guess is too high")

else:

print("You got it!!")

guess=int(input("Guess again: "))

print("You figured it out in ",guesscount," guesses")

Part 2: C++ code; rewrite the following code in C#. Run the program and submit. - include comments

#include <iostream>

using namespace std;

int main()

{

int count=1, total=0;

while(count<=100)

{

total +=count;

count++;

}

cout<<"The sum of the numbers 1 - 100 is "<<total<<endl;

return 0;

}

So i have used youed you guys a lot and none of you have been able to answer any of my questions correctly. I need this code to be 100 percent right if you can not do it dont submit it back to me. I also need it IN DETAIL WHAT YOU DID IN A PARAGRAPH IF YOU CANT DO THIS DO NOT RETURN IT TO ME.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

part 1.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text.RegularExpressions;

namespace myGame

{

    public class Game

    {

        public static void Main(string[] args)

        {

            int number = 4;

            int guesscount = 0;

            Console.WriteLine("Guess a number between 1 and 10 : ");

            // scan the number

            int guess = Convert.ToInt32(Console.ReadLine());

           

            // indefinite loop

            while(true)

            {

                // increment the number of guesses

                guesscount++;

               

                // if guessed number is less than the ans

                if(guess<number)

                    Console.WriteLine("Your guess is too low");

                // if guessed number is more than the ans

                else if(guess>number)

                    Console.WriteLine("Your guess is too high");

                // if guessed number is correct

                else

                {

                    Console.WriteLine("You got it");

                    // break out of loop

                    break;

                }

               

                Console.WriteLine("Guess again");

                // scan the number

                guess = Convert.ToInt32(Console.ReadLine());

            }

           

            Console.WriteLine("You figured it out in " + guesscount + " guesses");

        }

    }

}

Sample Output:

Part 2.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text.RegularExpressions;

namespace mySolution

{

    public class Solution

    {

        public static void Main(string[] args)

        {

         

          int count=1, total=0;

         

          while(count <= 100)

          {

            total +=count;

            count++;

          }

         

          Console.WriteLine("The sum of the numbers 1 - 100 is " + total);

        }

    }

}

Sample output:

Add a comment
Know the answer?
Add Answer to:
Part 1: Python code; rewrite this code in C#, run the program and submit - include...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...

  • In python how could I update my code to tell me the number of guesses it...

    In python how could I update my code to tell me the number of guesses it took my to get the correct number here is my working code so far import random number = random.randint(1,100) total_guess = 0 while total_guess<=100: guess = int(input("what is your guess?")) print (guess) total_guess = total_guess + 1 if guess<number: print("Too low") if guess>number: print("Too high") if guess==number: print("Correct!") break

  • lab5 is to rewrite lab1 by oop the code down below is the code of lab1...

    lab5 is to rewrite lab1 by oop the code down below is the code of lab1 Lab 5 Rewrite the program in Lab 1 in object-oriented programming. You need to analyze the functionalities in Lab 1. You may define any number of classes if necessary. For example, you can consider in this way: one object for the game procedure, the other object for the player. In this way, you should define a protocol so that the game object has minimal...

  • Can someone please rewrite this code using a while loop? Please write it in python. #The...

    Can someone please rewrite this code using a while loop? Please write it in python. #The winning number my_number = 12 #variable for the input name user_n = input("Hello! What is your name?") #Ask the user print("Well",user_n,": I am thinking of a number between 1 and 20." + "Take a guess.") user_n = float(input("Take a guess.")) #if statements if user_n == my_number: print("Good job" ,user_n, "You guessed my number!") if user_n > my_number: print("Your guess is high. You lose.") if...

  • This is the source code: Please incorporate the Exception Handling import javax.swing.JOptionPane; import java.awt.*; public class...

    This is the source code: Please incorporate the Exception Handling import javax.swing.JOptionPane; import java.awt.*; public class GuessingGame { public static void main(String[] args) { int computerNumber = (int) (Math.random() * 10 + 1); System.out.println("The correct guess would be " + computerNumber); int userAnswer = 0; int count = 0; while (computerNumber != userAnswer) { count++; String response = JOptionPane.showInputDialog(null, "Enter a guess between 1 and 10"); userAnswer = Integer.parseInt(response); String result = null; if (userAnswer == computerNumber) { result =...

  • Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that...

    Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that uses iteration to guess a number from 1 to 10. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and to turn in three things: 1) the pseudocode, 2) a screenshot of the output, and 3) the Python program. Instructions Write pseudocode for a Python program that uses iteration to guess a number from...

  • 1. program to use with number 1. 2. Comparing Python and Java Discussion Forum 14 days ago Use the Python...

    1. program to use with number 1. 2. Comparing Python and Java Discussion Forum 14 days ago Use the Python IDLE editor to create the source code for the "numberguess.py" pro- gram. This program is in the "Basic Python Pro- gramming" chapter in its "An Example Python Program: Guessing a Number" section. If you mistakenly create syntax errors, find and fix them. Run the program and test it with various values. Refer to the "numberguess.py Program document to see example...

  • Code comments explain and facilitate navigation of the code python import sys rentalcode = input("(B)udget, (D)aily,...

    Code comments explain and facilitate navigation of the code python import sys rentalcode = input("(B)udget, (D)aily, or (W)eekly rental?\n").upper() if rentalcode == 'B' or rentalcode == 'D': rentalperiod = int(input("Number of Days Rented:\n")) else: rentalperiod = int(input("Number of Weeks Rented:\n")) # Pricing budget_charge = 40.00 daily_charge = 60.00 weekly_charge = 190.00 #Second Section 2 odostart =int(input("Starting Odometer Reading:\n")) odoend =int(input("Ending Odometer Reading:\n")) totalmiles = int(odoend) - int(odostart) if rentalcode == 'B': milecharge = 0.25 * totalmiles if rentalcode == "D":...

  • #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0));...

    #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0)); int number, guess, response, reply; int score = 0 number = rand() % 100 + 1; do { do { cout << "Enter your guess "; cin >> guess; score++; if (guess < number) cout << guess << " is too low! Enter a higher number. "; else if (guess > number) cout << guess << " is too high! Enter a lower number....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT