I'm so sorry to hear that, I hope you're holding up ok
It depends on the type of pneumonia your nan has as to whether its contagious. Viral pneumonia (especially if its caused by the flu virus) is more contagious, but is still still relatively rare for it to be passed from person to person if they are otherwise healthy. People usually get pneumonia if they've had a cold and so their defences are down and they can then second a second infection leading to pneumonia.
Best thing to do is to ring the ward your nan is on or ask to speak to a doctor before you see her. If you're really worried you can wear a mask while you're in there as well, but if you're healthy the chances of catching it are pretty low
Hope that helps (still a med student so knowledge isn't that great yet)