I'm trying to tackle a challenge on Sololearn where I need to write a program that prints 'accepted' if the input is either 'amex' or 'visa' and does absolutely nothing for any other input. Here's what I came up with so far:
```python
card_type = input()
if card_type == 'amex' or 'visa':
print('accepted')
else:
print('')
```
I attempted to modify it like this to check if the first part works:
```python
card = input()
if card == 'amex' or 'visa':
print('accepted')
```
But this returned 'accepted' for any input, not just the specific card types I'm looking for. I also tried this piece of code:
```python
card = input()
if card != 'amex' and card != 'visa':
print('')
```
which performed as expected, but I'm stuck with the first condition leading to unexpected outputs. I just started programming and have been trying multiple approaches without success, and it's frustrating since Sololearn wants a subscription for more help!
3 Answers
Don't forget about indentation! Python relies heavily on whitespace to determine blocks of code. Make sure your `print` statements are properly indented to be part of the `if` or `else` statement. For example, this:
```python
if thing:
print('cow')
```
will behave differently from:
```python
if thing:
print('cow')
```
The first version is the correct one!
You nailed it, but really think about what you're asking with your conditionals. `if card == 'amex' or 'visa'` is fundamentally different from `if card == 'amex' or card == 'visa'`. The second condition checks for both explicitly. To clarify, the string 'visa' always evaluates to true on its own, leading to misleading results. If you want tighter checks, make sure to use the proper boolean logic in your conditions!
It looks like there's a misunderstanding in your conditional statements. When you have `if card == 'amex' or 'visa':`, the check for 'visa' isn't connected to your variable `card`. The condition actually always evaluates as true because strings like 'visa' always return true if assessed as a boolean. Instead, you should write it like this: `if card == 'amex' or card == 'visa':`. This way, you're explicitly checking the value of `card` against both options!

I did fix it! But is it common to feel confused all the time when first learning to code?