<!-- Day page sponsor slot: empty, so nothing is shown. When sold, add the line below
     right under this comment. Logo 120x40 px (send 240x80), text up to 60 characters:
     <p align="right"><sub>Sponsored</sub><br><a href="URL?ref=github-day-15"><img src="../assets/sponsors/NAME.png" height="40" align="middle" alt="NAME"></a>&nbsp; <a href="URL?ref=github-day-15">One-line message →</a></p> -->

<!-- day-nav:top -->
<p align="center"><a href="Day_14.md">← Day 14</a> &nbsp;·&nbsp; <a href="../README.md#days">All 24 days</a> &nbsp;·&nbsp; <a href="Day_16.md">Day 16 →</a></p>
<!-- /day-nav:top -->

# Question 54

### **Question**

> **_Assuming that we have some email addresses in the "username@companyname.com" format, please write program to print the company name of a given email address. Both user names and company names are composed of letters only._**

> **_Example:
> If the following email address is given as input to the program:_**

```
john@google.com
```

> **_Then, the output of the program should be:_**

```
google
```

> **_In case of input data being supplied to the question, it should be assumed to be a console input._**

---

### Hints

> **_Use \w to match letters._**

---

<details markdown="1">
<summary><b>💡 Show solutions</b> (try it yourself first!)</summary>

**Main author's Solution: Python 2**

```python
import re
emailAddress = raw_input()
pat2 = "(\w+)@(\w+)\.(com)"
r2 = re.match(pat2,emailAddress)
print r2.group(2)
```

---

**My Solution: Python 3**

```python
import re

email = "john@google.com elise@python.com"
pattern = "\w+@(\w+).com"
ans = re.findall(pattern,email)
print(ans)
```


</details>

---

# Question 55

### **Question**

> **_Write a program which accepts a sequence of words separated by whitespace as input to print the words composed of digits only._**

> **_Example:
> If the following words is given as input to the program:_**

```
2 cats and 3 dogs.
```

> **_Then, the output of the program should be:_**

```
['2', '3']
```

> **_In case of input data being supplied to the question, it should be assumed to be a console input._**

---

### Hints

> **_Use re.findall() to find all substring using regex._**

---

<details markdown="1">
<summary><b>💡 Show solutions</b> (try it yourself first!)</summary>

**Main author's Solution: Python 2**

```python
import re
s = raw_input()
print re.findall("\d+",s)
```

---

**My Solution: Python 3**

```python
import re

email = input()
pattern = "\d+"
ans = re.findall(pattern,email)
print(ans)
```

**OR**

```python
email = input().split()
ans = []
for word in email:
    if word.isdigit():     # can also use isnumeric() / isdecimal() function instead
       ans.append(word)
print(ans)
```

**OR**

```python
email = input().split()
ans = [word for word in email if word.isdigit()]  # using list comprehension method
print(ans)
```


</details>

---

# Question 56

### **Question**

> **_Print a unicode string "hello world"._**

---

### Hints

> **_Use u'strings' format to define unicode string._**

---

<details markdown="1">
<summary><b>💡 Show solutions</b> (try it yourself first!)</summary>

**Main author's Solution: Python 2**

```python
unicodeString = u"hello world!"
print unicodeString
```


</details>

---

# Question 57

### **Question**

> **_Write a program to read an ASCII string and to convert it to a unicode string encoded by utf-8._**

---

### Hints

> **_Use unicode()/encode() function to convert._**

---

<details markdown="1">
<summary><b>💡 Show solutions</b> (try it yourself first!)</summary>

**Main author's Solution: Python 2**

```python
s = raw_input()
u = unicode( s ,"utf-8")
print u
```

---

**My Solution: Python 3**

```python
s = input()
u = s.encode('utf-8')
print(u)
```


</details>

---

# Question 58

### **Question**

> **_Write a special comment to indicate a Python source code file is in unicode._**

---

### Hints

> **_Use unicode() function to convert._**

---

<details markdown="1">
<summary><b>💡 Show solutions</b> (try it yourself first!)</summary>

**Solution:**

```python
# -*- coding: utf-8 -*-
```


</details>

---

# Question 59

### **Question**

> **_Write a program to compute 1/2+2/3+3/4+...+n/n+1 with a given n input by console (n>0)._**

> **_Example:
> If the following n is given as input to the program:_**

```
5
```

> **_Then, the output of the program should be:_**

```
3.55
```

> **_In case of input data being supplied to the question, it should be assumed to be a console input._**

---

### Hints

> **_Use float() to convert an integer to a float.Even if not converted it wont cause a problem because python by default understands the data type of a value_**

---

<details markdown="1">
<summary><b>💡 Show solutions</b> (try it yourself first!)</summary>

**Main author's Solution: Python 2**

```python
n=int(raw_input())
sum=0.0
for i in range(1,n+1):
    sum += float(float(i)/(i+1))
print sum
```

---

**My Solution: Python 3**

```python
n = int(input())
sum = 0
for i in range(1, n+1):
    sum+= i/(i+1)
print(round(sum, 2))  # rounded to 2 decimal point
```
---
```python
'''Solution by: lcastrooliveira
'''
def question_59(n):
    print(round(sum(map(lambda x: x/(x+1), range(1, n+1))), 2))

question_59(5)
```

```python
'''Solution by: naveen675
'''
###   List Comprehension ###
print(round((sum(i/(i+1) for i in range(1,int(input())+1))),2))

                        ## OR  ##

print(round(sum(map(lambda i:i/(i+1),[*range(1,int(input())+1)])),2))
```

</details>

---

<!-- day-nav:bottom -->
<p align="center">
<sub><b>UP NEXT</b></sub><br>
<a href="Day_16.md"><img src="../assets/days/day-16.svg" width="240" alt="Day 16, questions 60 to 64: Recursion &amp; Fibonacci"></a><br>
<a href="Day_14.md">← Day 14</a> &nbsp;·&nbsp; <a href="../README.md#days">All 24 days</a>
</p>
<!-- /day-nav:bottom -->

[**_Discussion_**](https://github.com/darkprinx/100-plus-Python-programming-exercises-extended/issues/3)
