a = int( ); b = float( ); c = str( ); d = bool( ); e = list( ); f = dict( ); print(a, b, c, d, e, f) # Output: 0 0.0 False [] {}You get the default value of each datatype. The empty string, which is the default value for str, does not appear because the output from print('') is not visible. To make it visible, you need print(repr('')).
(3, 4) + (5, 6) = (8, 10) (3, 4) * 2 = (6, 8)Translated to Python, this is
p1 = new Pair(3, 4) p2 = new Pair(5, 6) print(p1 + p2, p1 * 2) # Output: (8, 10) (6, 8)Ans: Here is the Pair class:
class Pair: def __init__(self, x, y): self.x = x self.y = y def __str__(self): return f'({self.x}, {self.y})' def __repr__(self): return str(self) def __eq__(self, other): return self.x == other.x and \ self.y == other.y def __add__(self, other): return Pair(self.x + other.x, \ self.y + other.y) def __mul__(self, other): return Pair(self.x * other, \ self.y * other)
Hand Type | Expected Counts | Actual Counts of One Run |
---|---|---|
No Pair | 50,118 | 50,198 |
One Pair | 42,257 | 42,052 |
Two Pair | 4,754 | 4,890 |
Three of a Kind | 2,113 | 2,183 |
Straight | 393 | 328 |
Flush | 197 | 187 |
Full House | 144 | 141 |
Four of a Kind | 24 | 20 |
Straight Flush | 1.5 | 1 |
> javac HelloWorld1.java
> java HelloWorld1
Language | How Compiled | Speed |
---|---|---|
C, C++ | Compiled to Native Executable | Fast |
Java, C#, Python1 | Compiled to Bytecode2 | Medium |
Ruby, R, Shell Script3 | Not compiled, executed by interpreter | Slow |