input code:
output:
code:
'''make a class Area'''
class Area:
'''constructor'''
def __init__(self):
self.x=0
'''set x method'''
def setX(self,n):
if n<-0:
raise ValueError
else:
self.x=n
'''try catch block'''
try:
'''make object'''
a=Area()
'''take user input'''
inputValue=int(input("Enter a Value that is grater than 0:"))
'''set x'''
a.setX(inputValue)
'''except for handle a exceptions'''
except ValueError:
'''print value'''
print("Invalid Input Value Entered")
(python) [30] Implement exception handling with ValueError here in the following code: There are three blanks...
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 =...
I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong? Thanks for any help! def even(n): if n%2==0 #Enter a Number def main(): n=int(input("Enter a number: ")) #If even print "Number is even" if(even(n)): print("The number is even") #If odd print "Number is odd" else: print("The number is odd") main() #Call the main function
PYTHON: Conan is writing a module to contain different implementations of trees. After his first tree, the BinaryTreeclass, he wrote test code and is having problems understanding the error. Locate his problem and explain how you would fix it. class Node(object): def __init__(self, data=None): self.data = data def __str__(self): return "NODE: " + str(self.data) class Tree(object): def __init__(self): self.root_node = None self.size = 0 def __len__(self): return self.size def add(self, data): raise NotImplementedError("Add method not implemented.") def inorder_traversal(self): raise NotImplementedError("inorder_traversal...
Create a two new gate classes, one called NorGate the other called NandGate. NandGates work like AndGates that have a Not attached to the output. NorGates work lake OrGates that have a Not attached to the output.Create a series of gates that prove the following equality NOT (( A and B) or (C and D)) is that same as NOT( A and B ) and NOT (C and D). Make sure to use some of your new gates in the...
The goal of this code is to draw a smiley face and be able to change emotion, mouth and eyes. Use the demo code below to fill in the blanks ( ), as well as add any other methods or data that is needed. All blanks should be completed with a single line of code (or partial line). You should not modify any other code that exists. Only remove the blanks and add other missing methods. Use a radius of...
Page 3 of 7 (Python) For each substring in the input string t that matches the regular expression r, the method call re. aub (r, o, t) substitutes the matching substring with the string a. Wwhat is the output? import re print (re.aub (r"l+\d+ " , "$, "be+345jk3726-45+9xyz")) a. "be$jk3726-455xyz" c. "bejkxyz" 9. b. "be$jks-$$xyz" d. $$$" A object a- A (2) 10. (Python) What is the output? # Source code file: A.py class A init (self, the x): self.x-...
I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i am recieving says that in line 61 list index is out of range. kindly someone help me with it as soon as possible. Below is the program kindly check and correct it. Thanks! class Animal: def __init__(self, name, types, species, mass): self.name=name self.type=types...
THIS IS THE CODE I AM TRYING TO RUN code # def main(): #Reading a as an integer a = int(input("Enter value for a: ")) #reading b as an interger b = int(input("Enter value for b: ")) #reading n as an integer n = int(input("Enter value for n: ")) # displaying if a and b are congruent modulo n, this is True if a and b #both returns same remainder when divided by n if a % n == b...
Python 3+ Adjust the following code so the two errors below are non-present: 1. __init__() : Since Pizza object don't have it's own set() datastructure, the toppings in the pizza object are manimupated from out of the object. (-1.0) 2. __eq__() : How about "self.toppings == other.toppings" rather than "self.toppings - other.toppin == set())". Code: ## Program 1 ## --------------------------------- class Pizza: def __init__(self, s='M', top=set()): self.setSize(s) self.toppings = top def setSize(self, s): self.size = s def getSize(self): return self.size...